ContentTypes is the right approach.
This is because the ForignKey can only point to one type of table so you need to pass through the an intermediate table and do your split depending on the different type.
So model inheritance for the class hierarchy, but ContentType for the foreign keys.
- In Django, how do you retrieve data from extra fields on many-to-many relationships without an explicit query for it?
If you only need to point to “any product,” not any model, then the solution is to have a Product model that all products inherit from (i.e. Television and Camcorder are both subclasses of Product), and give your Offer model a ForeignKey to Product.
- How to use pytest fixtures with django TestCase
- Django unique together constraint failure?
- Django rest auth email instead of username
- How do I convert kilometres to degrees in Geodjango/GEOS?
- How do Django forms sanitize text input to prevent SQL injection, XSS, etc?
Take a look at django-polymorphic, this implements this feature, and also uses ContentTypes internally.
- Why is post_save being raised twice during the save of a Django model?
- Deploying Django project with Gunicorn and nginx
- Django: define a name for reverse ForeignKey