0

考虑以下模型:

class FPModel(models.Model):
    # The user who created
    author = models.ForeignKey(auth.models.User, null=False)
    # The user who last edited
    editor = models.ForeignKey(auth.models.User, null=True)
    # Create Time
    created_at = models.DateTimeField(auto_now_add=True)
    # Modify Time
    edited_at = models.DateTimeField(auto_now=True)

    class Meta:
        abstract = True

我将从 django admin 自动填充作者和编辑器字段。

当我同步数据库时,我收到以下错误:

(pinax-env)gautam@Aspirebuntu:$
 python manage.py syncdb
Error: One or more models did not validate:
FP.fpmodel: Accessor for field 'author' clashes with related field 'User.fpmodel_set'. Add a related_name argument to the definition for 'author'.
FP.fpmodel: Accessor for field 'editor' clashes with related field 'User.fpmodel_set'. Add a related_name argument to the definition for 'editor'.

我正在使用django 1.2.5pinax 0.7.2

我应该怎么做才能解决这个问题?

4

1 回答 1

0

我从文档中找到了答案,特别是这里这里

我必须使用

author = models.ForeignKey(auth.models.User , null = False ,related_name="%(class)s_related_author" ) # The user who created 
editor = models.ForeignKey(auth.models.User , null = True,related_name="%(class)s_related_editor" ) # The user who last edited
于 2011-09-10T04:36:18.980 回答