Distinguishing parent model's children with Django inheritance

后端 未结 3 2089
臣服心动
臣服心动 2021-01-24 06:12

Basically I have a Base class called \"Program\". I then have more specific program model types that use Program as a base class. For 99% of my needs, I don\'t care whether or n

3条回答
  •  借酒劲吻你
    2021-01-24 06:39

    A couple of weeks ago, someone on the django-developers mailing list introduced a very interesting extension to Django's ORM that makes QuerySets return subclassed objects instead of objects of the parent class. You can read all about it here:

    http://bserve.webhop.org/wiki/django_polymorphic

    I haven't tried it myself yet (but certainly will), but it seems to fit your use case.

提交回复
热议问题