在代理模型上使用InheritanceManager(django-model-utils)

时间:2013-08-17 16:30:23

标签: django django-models polymorphism

我正在使用django-model-utils中的InheritanceManager在查询期间获取给定Django模型的子类:

from django.db import models
from model_utils.managers import InheritanceManager

class Generic(models.Model):

    objects = InheritanceManager()

    def template(self):
        return 'Generic.html'

class Specific(Generic):

    def template(self):
        return 'Specific.html'

    class Meta:
        proxy = True

我打电话

Specific.objects.create()
try:
    print Generic.objects.get().template()
    print Specific.objects.get().template()
    print Generic.objects.select_subclasses().get().template()
finally:
    Specific.objects.get().delete()

,输出

Generic.html
Specific.html
Generic.html  # <--- why isn't this specific? I'm calling for subclasses.

我做错了什么?

0 个答案:

没有答案