0
votes

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'.
1
can you provide the error traceback ?Linh Nguyen
sure,I updated question with errorAnoop K George

1 Answers

2
votes

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