On 7/07/2019 9:07 am, Shazia Nusrat wrote:
Hi All,
I am having hard time to get multiple roles for users in a project and
I am having errors.
I've added related_name but still getting error. Can please tell me
how to fix this?
The error provides a hint. You need an extra argument ...
related_name='user_role'
... or something else which makes sense for you in the context of your
app. See ...
https://docs.djangoproject.com/en/2.1/ref/models/fields/#django.db.models.ForeignKey.related_name
Mike
*******************************************
from django.db import models
from django.contrib.auth.models import AbstractUser
# Create your models here.
class Role(models.Model):
STUDENT = 1
TEACHER = 2
SECRETARY = 3
SUPERVISOR = 4
ADMIN = 5
ROLE_CHOICES = (
(STUDENT, 'student'),
(TEACHER, 'teacher'),
(SECRETARY, 'secretary'),
(SUPERVISOR, 'supervisor'),
(ADMIN, 'admin'),
)
id = models.PositiveSmallIntegerField(choices=ROLE_CHOICES,
primary_key=True)
def __str__(self):
return self.get_id_display()
class User(AbstractUser):
roles = models.ManyToManyField(Role)
*******************************************************
I am getting error below:
*******************************************************
ERRORS:
auth.User.groups: (fields.E304) Reverse accessor for 'User.groups'
clashes with reverse accessor for 'User.groups'.
HINT: Add or change a related_name argument to the definition
for 'User.groups' or 'User.groups'.
auth.User.user_permissions: (fields.E304) Reverse accessor for
'User.user_permissions' clashes with reverse accessor for
'User.user_permissions'.
HINT: Add or change a related_name argument to the definition
for 'User.user_permissions' or 'User.user_permissions'.
users.User.groups: (fields.E304) Reverse accessor for 'User.groups'
clashes with reverse accessor for 'User.groups'.
HINT: Add or change a related_name argument to the definition
for 'User.groups' or 'User.groups'.
users.User.user_permissions: (fields.E304) Reverse accessor for
'User.user_permissions' clashes with reverse accessor for
'User.user_permissions'.
HINT: Add or change a related_name argument to the definition
for 'User.user_permissions' or 'User.user_permissions'.
***********************************************************
Looking forward for your kind help.
Thanks,
Shazia
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAD83tOyrfzvb3JCrgUFPUqTpxiaf-qLvy50nhgOLgA%2BpsjbURQ%40mail.gmail.com
<https://groups.google.com/d/msgid/django-users/CAD83tOyrfzvb3JCrgUFPUqTpxiaf-qLvy50nhgOLgA%2BpsjbURQ%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/02eff74f-5862-754b-6dd3-6f2df83cb842%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.