If I have
class Foo(models.Model):
widgets = models.ForeignKey('widgets.Widget', related_name='widgets')
I want to save a subclass, XWidget of Widget to the database. Is this ok, even though Foo.widgets is of the Widget parent class not XWidget?
When reading Foo.widgets, if I want to find all XWidgets is a filter a good way to do this?
Cheers
Yes, you may save a subclass to a foreign key referencing its parent, because
XWidgetis-aWidget. It won’t work in reverse, though. For instance, if your foreign key was to ‘widgets.XWidget’, you couldn’t save aWidgetto it.