Django模型相关的Field Clash

时间:2011-09-10 04:35:42

标签: django-models pinax

考虑以下模型:

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

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

1 个答案:

答案 0 :(得分:0)

我找到了文档的答案,特别是herehere

我必须使用

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