There is a set of objects: Obj1, Obj2, Obj3. They have some common parameters and some specific to each type. The common ones are stored in the same common_parameters table, and those specific in params1, params2 and params3, respectively. Tell me how to describe the model classes in such a way that each class contains both common and specific fields, and so that when you save, update two tables? If this is at all possible.
2 answers
If I understand correctly, then model inheritance will suit you
class Common(models.Model): common_param_1 = common_param_2 = class Obj1(Common): spec_param_1 = spec_param_2 = class Obj1(Common): spec_param_1 = spec_param_2 = A one-to-one relationship is implicitly created between models.
- thanks, what you need - djudman
|
You can link via ForeignKey, the object will have 3 fields with foreign keys and a null value is allowed. It turns out cumbersome, but the condition is fulfilled: an object can have properties from any three params1-3 tables.
Honestly, I do not like the option I have proposed, but nothing else comes to mind.
|