Django Model Inheritance query a central table

后端 未结 1 412
孤独总比滥情好
孤独总比滥情好 2020-12-20 01:37

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

相关标签:
1条回答
  • 2020-12-20 01:54

    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.

    0 讨论(0)
提交回复
热议问题