Hi fellow stackers,
I'd like to ask about the most elegant approach when it comes to designing models with virtual fields such as below in Django...
Let's say we're building an online store and all the products in the system are defined by the model "Product".
class Product(models.Model):
# common fields that all products share
name = ...
brand = ...
price = ...
But the store will have lots of product types completely unrelated with eachother, so I need some way to store those virtual fields of different product types (ie. capacity of a MP3 player, pagecount of a book,..).
The solutions I could come up with my raw Django skills are far from perfect so far:
Having a "custom_fields" property and intermediate tables that I manage manually. (screaming ugly in my face :))
Or inheriting classes from "Product" on the fly with Python's dangerous exec-eval statements (that is too much voodoo magic for maintenance and also implementation would require knowledge of Django internals).
What's your take on this?
TIA.