开发者

django - order_with_respect_to recursive foreign key

I am using Django 1.2.3. I have a table that represents categories and subcategories. For subcategories, it just references a 'parent' primary key from its own table as its parent. It looks something like this:

class Category(models.Model):
    def __unicode__(self):
        return self.name
    class Meta:
        db_tablespace = 'Category'
        verbose_name = 'Category'
        verbose_name_plural = 'Categories'
        ordering = ['display_weight', 'name']
        order_with_respect_to = 'parent'
    name = models.CharField('Category Name', max_length=32)
    parent = models.ForeignKey('self', blank=True, null=True)
    display_weight = models.IntegerField('Display Weight', default=50)

WHen I attempt to validate/sync this database, I get the following error:

AttributeError: 'str' object has no att开发者_开发百科ribute 'get_category_order'

It seems that it won't let me order with respect to a "foreign key" that is recursive. Can anyone explain this. Is there a way around this? There might be several levels of categories and subcategories, but there will never be cyclic references defined in the table.


This changeset shows that the your issue has been fixed in the version of django you are using. It is a backport of this changeset.

The issue is discussed here in these tickets:

http://code.djangoproject.com/ticket/2740

http://code.djangoproject.com/ticket/13241

You might want to check if your django has the patched code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜