You are not logged in.

Change Language:

Board » Django » Models » Reverse query name for field [...] clashes with related field [...]

Hello all, I have a very unusual problem, because of an specific modelling.
I have created an abstract base class which looks like this:

class BaseModel(models.Model):
    user_added = models.ForeignKey(User, null=True, related_name='user_added')
    user_modified = models.ForeignKey(User, null=True, related_name='user_modified')
    class Meta:
        abstract = True


Basically, my idea was that every model that descends from it gets has two tracking fields, so that I know which user added and last modified the record. However, when I descend more than one class from it, I get the following message (several times, one for each descending class):
(class name): Reverse query name for field 'user_modified' clashes with related field 'User.user_modified'. Add a related_name argument to the definition for 'user_modified'.


Is there a way to do what I want? Or an alternative?
hi,
according to the django documentaiton something like the following should work:

class BaseModel(models.Model):
    user_added = models.ForeignKey(User, null=True, related_name='%(class)s_user_added')
    user_modified = models.ForeignKey(User, null=True, related_name='%(class)s_user_modified')
    class Meta:
        abstract = True

This answers the question. (Voted by 1 users including the author of the question.)
Hey thanks!
It works perfectly.





Powered by Sphene Community Tools