I need to implement a fairly standard entity-attribute-value hierarchy. There are devices of multiple types, each type has a bunch of settings it can have, each individual device has a set of particular values for each setting. It seems that both django-eav and eav-django packages are no longer maintained, so I guess I need to roll my own. But how do I architect this? So far, I am thinking something like this (skipping a lot of detail)
class DeviceType(Model): name = CharField() class Device(Model): name = CharField() type = ForeignKey(DeviceType) class Setting(Model): name = CharField() type = CharField(choices=(('Number', 'int'), ('String', 'str'), ('Boolean', 'bool'))) device_type = ForeignKey(DeviceType) class Value(Model): device = ForeignKey(Device) setting = ForeignKey(Setting) value = CharField() def __setattr__(self, name, value): if name == 'value': ... do validation based on the setting type ... def __getattr__(self, name): if name == 'value': ... convert string to whatever is the correct value for the type ...
Am I missing something? Is there a better way of doing this? Will this work?