I have some objects which will be used in the same manor. This object is categorised in predefined types of this object. Each type has properties belonging to this type of the object.
To get this in a model, I had this tables for the model in mind:
- One table with the types of the object
- One table with the predefined properties belonging to the type (with a description/help text of the field, is the property requierd, the type of the field and so on)
- One table with the objects with a relation to the table with its
properties (the next one in this list) - One table with the properties of the objects and it values (refering to the
predefined properties for its definition)
it does work, but needs some programming to keep things together.
another issue with this solution is the fieldtype of the property, this can be different. So or I’ll use 1 field type (charField) and try to parse it, or I’ll have a table with different value fields with the most used field types (value_integer = models.IntegerField). In this case you get a lot of emtpy fields just to have 1 of the fields filled in per property. Actually I Am looking for some kind of dictionary…
Not sure whether this is the right way to go….any suggestions?
Django’s way to go is to define one model class per object type, as expected by all Django’s features (admin, forms, external apps …).
You can define a superclass and use model inheritance, e.g:
There, you can predefine defaults as usual.
If you want your user to create their classes in the admin then consider another framework (eZ Publish suits this need for example).