考虑以下模型:
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.5
和pinax 0.7.2
。
我该怎么做才能解决这个问题?
我从文档中找到了答案,特别是这里和这里。
我必须使用
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