1👍
Use inheritance: define a superclass for Company, with the common fields, and then inherit that class and add the stuff ClassACompany and ClassBCompany need.
This way the UserProfile can have a foreign key to Company. If you need to get from the company to the specific type of company, you can do that as described in the docs.
1👍
why dont you just have one class for Company? that’ll make your system much, much simpler.
you can then have specific fields inside Company that will let you determine whether it’s of type A or B (what’s the difference anyway?)
- [Answered ]-Django rest_framework serializer with inner relationship
- [Answered ]-UniqueValidator with source field
- [Answered ]-How to increase performance for forms?
0👍
If you really must have different fields inside CompanyA and CompanyB then you can have them both derive from a common Company class which your ForeignKey will point to.
0👍
You would need to reference the Company model, and if need be, subclass Company with CompanyA and CompanyB. For simplicity, your Company class could have a type
attribute with possible A
and B
values, then you could avoid subclassing.
- [Answered ]-Postgresql slow join even with index?
- [Answered ]-Django running in virtualenv gives syntax error after executing /usr/share/qgis… (not in virtualenv)