【问题标题】:Django Model related Field ClashDjango 模型相关字段冲突
【发布时间】:2011-09-10 04:35:41
【问题描述】:

考虑以下模型:

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

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

【问题讨论】:

    标签: django-models pinax


    【解决方案1】:

    我从文档中找到了答案,特别是 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
    

    【讨论】:

    • 两者都是“找不到页面”链接。请提供更新的链接
    猜你喜欢
    • 2013-11-09
    • 2018-01-15
    • 2010-11-11
    • 2022-10-24
    • 2014-12-03
    • 2014-12-22
    • 2011-07-30
    • 2016-03-09
    相关资源
    最近更新 更多