我正在使用Django 1.2.3。我有一個代表類別和子類別的表格。對於子類別,它只是將其自己的表中的「父」主鍵引用爲其父項。它看起來是這樣的:django - order_with_respect_to遞歸外鍵
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)
,當我嘗試驗證/ SYNC這個數據庫,我收到以下錯誤:
AttributeError: 'str' object has no attribute 'get_category_order'
看來,它不會讓我對於訂購「外鍵」是遞歸的。任何人都可以解釋一下有沒有解決的辦法?可能有幾個級別的類別和子類別,但是永遠不會在表格中定義循環引用。
這很奇怪,我試過用南,它工作得很好。你在Django項目中使用South嗎? – 2011-04-04 00:50:34