python - Django dynamic embedded/nested models -


i have application knows type of entity @ creation time. because of don't know how link associated models see like

  • have type embedded json field attribute entity
  • have relation between 'fixed' tables (see bellow)

the e_type field simple charfield, based on value has, query type_a or type_b.

this how looks django

class entity(models.model):    name = models.charfield(max_lenght=64)    e_type = models.charfield(max_lenght=1)  class type_a(models.model):    entity = models.onetoonefield(entity)    attribute = models.charfield(max_lenght=64)  class type_b(models.model):    entity = models.onetoonefield(entity)    attribute = models.charfield(max_lenght=64) 

what suggest ?

thanks

edit: in response of why multiple tables - each e_type referees different table structure. example type_a has 4 fields, type_b has ten fields , on. having json field simple since can store data no need have multiple tables each it's own structure. different option can see use eav.

i not sure if interpreting question correctly, perhaps, using inheritance, this...

class entity(models.model):     name = models.charfield(max_length=64)     # other parent attributes.  class entitya(entity):     # unique attributes.  class entityb(entity):     # unique attributes. 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -