Example situation as follows:
# models.py
class Form(models.Model):
name = models.CharField()
class A(models.Model):
form = models.ForeignKey(Form)
class B(A):
name = models.CharField()
# view.py
form = Form.objects.get(id=1)
form.a_set.all() # works
form.b_set.all() # doesn't work
I would like to access all the related B
Objects via the parent class A
foreign key but I can't seem to do this. And if I access them via A
then I just get the generic parent class query set. Thank you.
When you inherit from a concrete model, there will be two tables (unlike inheriting from an abstract model) for
Parent
andChild
models.Django will implicitly create a
OneToOneField
fromChild
toParent
model namedparent_ptr
, thus:will give you the desired
QuerySet
.