Retrieving child models

I have an app called Blog. In my there is a class BaseEntry and classes that inherit from it like SimpleEntry and TitledEntry. For the index view I want all the Entries in one list.

I defined my list view like this.

class BlogListView(ListView):
    model = BaseEntry
    template_name = 'blog/index.html'
    paginate_by = 5

I’m thinking I could do something like this:


Then I could go through the list and retrieve the child instances by their parents ids.

Or instead I could do something like this right away:


The thing that bothers me: I define the view to work with a particular model, but then I work with a different model. On the other hand the documentation says this:
“A QuerySet that represents the objects. If provided, the value of queryset supersedes the value provided for model .”
Am I taking the model attribute too serious or could I run into trouble with thie second approach?

Remember that the relationship between a concrete base class and a child class is the establishment of a OneToOne relationship from the child class to the parent.

This means that you can do something like BaseEntry.objects.all(), and then check to see whether a particular instance has an attribute simpleentry or titledentry to identify which child class is related to it.

1 Like

django-model-utils’ InheritanceManager may help with resolving child models:

However, with too many different child models you may run into performance trouble because of too many outer joins. But it might just work really well and solve your problem.