I have an application that knows about a type of an entity at creation time. Because of this I don't know how to properly link the associated models however I see it like
- have the type embedded into a json field as an attribute for Entity
- have some relation between 'fixed' tables (see bellow)
The e_type field is a simple CharField, based on what value it has, I query Type_a or Type_b.
This is how it looks now into 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 would you suggest ?
thanks
Edit: In response of why are multiple tables - each e_type referees to a different table structure. For example type_a has four fields, type_b has ten fields and so on. Having a json field is simple since it can store any data so no need to have multiple tables each with it's own structure. A different option I can see is to use something like EAV.