1👍
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
0👍
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:
Post
The Docs:
- How can I create a new Django instance using reverse-foreign key without saving it to DB?
- Django Form Validators on Comparing One Object Against Another
Source:stackexchange.com