Skip to content Skip to sidebar Skip to footer

Django Model Inheritance Query A Central Table

I have a solution that I thought I could take care of model inheritance, but now looking at it again it doesn't actually solve my problem. What I would like is to be able to call

Solution 1:

I haven't used it, but this project looks like what you're looking for: https://code.google.com/p/django-polymorphic-models/

You can request LessonModule.objects.all() and then .downcast() each object automatically into a ProfileImage or a Note.

Or add the PolymorphicMetaclass to your LessonModule to always retrieve ProfileImage and Note objects from a queryset.

Note the cost of extra queries... polymorphism in Django models is done via table joins, not pure python code.

Post a Comment for "Django Model Inheritance Query A Central Table"