I have a django application which has one main table/model which references various ‘lookup’ tables. So for example : Client is the main table and it references the TitleCode, OccupationCode etc etc via a foreign key relationship. The ‘lookup’ tables are all pretty similar in structure (PK,Code,Display_Value). The obvious way to do this in django is to have an explicit class deriving from model.Models for each lookup table. It becomes a bit repetitive and when you have semi-custom admin forms for each table then its even more cumbersome. Any ideas? I was thinking of creating a base class implementing the actual model definition in the base and then to derive the specific lookup tables/models from these base classes. I’m going to check if this is doable now…
I have a django application which has one main table/model which references various ‘lookup’
Share
Just create an abstract model called Code and inherit the specific classes from it (TitleCode, OccupationCode, etc…). ModelForms can be used for all of them, not much code.
Another solution would be to just make a Code class and a CodeType class…put all fields in there that you might need, making them optional if they are in some types and not others. Then the Code object would have a FK to CodeType.