I'm trying to provide for users possibility to store in SomeModel a list of ExtraParameters of any number or kind (it may be something small like IntegerField, BooleanField or quite large like TextField).
I tried to implement ExtraParameter abstract model class, that will keep ForeignKey to SomeModel, and also its child classes with only one parameter like:
class ExtraParameter(models.Model):
somemodel = models.ForeignKey(SomeModel, ...)
class Meta:
abstract = True
class IntegerExtraParameter(ExtraParameter):
value = models.IntegerField()
I believe it takes multiple small classes like this one so it could be migrated to multiple database tables of different fields.
Am I right? Please provide better solution. Maybe other way to decorate ExtraParameter is possible?
The problem with this approach is while implementing template it is not so easy to get all the stored parameters of all kind by doing somemodel.extraparameters.all(), rather I need to call every child class explicitly and build set from it. But also I've seen a solution with finding all subclasses of any class inside app's config, so it would help.
Jakub