开发者

Django Model related Field Clash

开发者 https://www.devze.com 2023-04-04 10:25 出处:网络
Consider the following model: class FPModel(models.Model): # The user who created author = models.ForeignKey(auth.models.User, null=False)

Consider the following model:

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

I will be auto-populating the author and editor fields from django admin.

When I sync the database I am getting the following error:

(pinax-env)gautam@Aspirebuntu:$
 python manage.py开发者_如何学Go 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'.

I am using django 1.2.5 and pinax 0.7.2.

What should I do to solve this?


I found the answer from the docs, specifically here and here.

I have to use

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
0

精彩评论

暂无评论...
验证码 换一张
取 消