[Fixed]-Django models field user and admin from the same model


Change code like this:

admin = models.ForeignKey(User, related_name='admin_user')
users = models.ManyToManyField(User, related_name='users_user')

Also see ForeignKey related_name


You’re creating different users attributes with the same backwards relationships
‘user_set’, and this doesn’t works.

Try it:

admin = models.ForeignKey(User)
users = models.ManyToManyField(User,related_name="+")

provide two different related_name attributes so that the backwards relationship attributes’ names don’t clash.

In this post, you can see the same problem:

The Docs:

Leave a comment