开发者

Problem inheriting get_absolute_url in an child model

I have the following sets of models (abbreviated for clarity):

First set:

class Web(Link):
    ideas = models.ManyToManyField(Idea, blank=True, null=True)
    precedents = models.ManyToManyField(Precedent, blank=True, null=True)

    categories = GenericRelation(CategoryItem)

    @permalink
    def get_absolute_url(self):
       return ('resources-link-detail', [str(self.slug)])

which is a child of:

class Link(models.Model):
    title = models.CharField(max_length=250)
    description = models.TextField(blank=True)
    website = models.URLField(unique=True)
    slug = models.SlugField(unique_for_date='pub_date')
    ...

    @permalink
    def get_absolute_url(self):
        return ('link-detail', [str(self.slug)])

Second set

class ResourceOrganization(Organization):
    ideas = models.ManyToManyField(Idea, blank=True, null=True)
    precedents = models.ManyToManyField(Precedent, blank=True, null=True)

    categories = GenericRelation(CategoryItem)

    @permalink
    def get_absolute_url(self):
        return ('resources-org-detail', [str(self.slug)])

which is a child of:

class Organization(Contact):
    name = models.CharField(max_length=100)
    org_type = models.PositiveSmallIntegerField(choices=ORG_CHOICES)
    ...

    @permalink
    def get_absolute_url(self):
        return ('org-detail', [str(self.slug)])

which is a child of:

c开发者_StackOverflowlass Contact(models.Model):
    description = models.TextField(blank=True, null=True)
    address_line1 = models.CharField(max_length=250, blank=True)
    address_line2 = models.CharField(max_length=250, blank=True)
    slug = models.SlugField(unique=True)
    ...

    class Meta:
        abstract = True

The "ResourceOrganization" model is properly overiding the get_absolute_url method and is adding the "categories" generic relation.

The "Web" model is not.

I'm at a loss to figure out why. Would appreciate any insight.

P.S. I'm realizing that there may have been better ways to implement this functionality, but I'm stuck with it for the moment until I can refactor and would like to get it working.

Thanks.


If anyone else is running into this problem, take a look at any custom managers you have defined on the parent model. They will not inherit to the child model in the way you might think.

http://docs.djangoproject.com/en/dev/topics/db/managers/#custom-managers-and-model-inheritance

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜