Field with inner structure in Django
I'd like to create a table of items in Django. The problem is that every
Item has different inner structure and I would have to create too many
tables.
For example if item will be CPU I'd like to have the inner structure
attribute (column) as follows:
type:processor
frequency:value
number of cores:value
socket:value
And if the item will be smartphone the inner structure would be:
type:smartphone
os:value
displaysize:value
cpuID:value
When adding new items to the database, the field should first ask the user
what type he wants to add (e.g. CPU) and according to this infomation
display the appropriate form for the inner structure attribute which
depends on type.
What are the approaches to implement this? Is there already some help in
Django for such data? What are the pros and cons of various approaches? So
far, I see one disadvantage. Note that smartphone uses cpuID as a foreign
key. Is it possible to preserve references? Note that CPU can have
reference to it's manufacturer (only an example that various items can
have a few references to other items).
No comments:
Post a Comment