0

My project is simple blog app where users can post,comment and like posts. I used Django default user registration page, later I add Djoser (third party token authentication for Django rest framework) with custom user model, it result in crash, please look into this

please note that if I avoid custom user for Djoser,my project works fine,ie I am able to register using token and session authentication

FORMS.PY #for Django's default register view

from django import forms
#from django.contrib.auth.models import User
from .models import User
from django.contrib.auth.forms import UserCreationForm

class UserRegisterForm(UserCreationForm):
    email = forms.EmailField()
    class Meta:
        model = User
        fields=['username','email','phone','first_name','last_name','password1','password2']

MODELS.PY # Djoser Custom user model

from django.db import models
from django.contrib.auth.models import AbstractUser
from django.conf import settings

class User(AbstractUser):
    email = models.EmailField(verbose_name='email' ,max_length=223,unique=True)
    phone=models.CharField(null=True,max_length=11)
    REQUIRED_FIELDS = ['username','phone','first_name','last_name']
    #USERNAME_FIELD = 'email'

    def get_username(self):
        return self.email

ERROR TRACEBACK

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'.
userapp.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'.
userapp.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'.
2
  • can you provide the error traceback ? Commented May 7, 2020 at 8:48
  • sure,I updated question with error Commented May 7, 2020 at 8:53

1 Answer 1

2

You have to add AUTH_USER_MODEL in your settings.py. Doing this will allow that your User model by default is changed and to new one. Hence, will work fine:

AUTH_USER_MODEL = 'APPNAME.MODELCLASSNAME'

In your case, AppName is the app inside where your models.py is located. It could be accounts or sthg like that:

AUTH_USER_MODEL = 'accounts.User'

Have a look at this beautiful documentation on customizing authentication User. customize_user_django

*Note: accounts is my guess on your app name which you did not specified, User is sure which you specified in models.py

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.