django - Can I dinamically add new fields to my models/serializer/db ? -


i´m developing application using django rest framework, , have problem. i´m trying make application flexible possible, wanted possibility dynamically add new fields models.
example:
have model robot fields id , version. user wants add new field, owner of robot. can can can make model , serializer reflect new field. can see how can easilly add new field database, model , serializer not reflect change.

i wanted possibility dynamically add new fields models.

short answer: can't.

long answer: can use related model each record represent "field" given robot instance, ie:

class robotfield(models.model):      robot = models.foreignkey(robot)      fieldname = models.charfield(max_length=30)      value = models.textfield()       class meta:          unique_together = [("robot", "fieldname")] 

but handling value (and it's type), validations, etc etc, , queries involving "fields" become pita.

or store "user-defined" fields json in kitchen-sink textfield, let's not talk of sql queries...

the point not, adding field schema means adding quite business domain code using field - because point of adding field support business rule.

fwiw peoples have tried come "zero-code user extensible models" apps years , yet have see app succeeded in doing so. results have ended in bloated code bases filled antipatterns (like storing user-written code , templates in db) , exhibiting abysmal runtime performances - , ui complex users pay developpers each time need of evolutions supposed able themselves, paying big bucks since bloated code base , convuluted models means simple adding simple fields in models takes 5 times more work.

iow : keep simple stupid - code quite simplest configuration tool.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -