Manager isn't available; User has been swapped for 'pet.Person'

前端 未结 4 652
误落风尘
误落风尘 2020-11-28 05:55

I\'m been using the default user model in django for quite a abit and I realize , if I need to further enhance it , I would have to create my own custom User Model in django

4条回答
  •  春和景丽
    2020-11-28 06:07

    For anyone else who might come across this problem, I also solved it by simply doing this on forms.py:

    add this at the top of the forms.py file

    from .models import YourCustomUser
    

    and then add this to your forms.py CustomUser form:

    class SignUpForm(UserCreationForm):
    #profile_year        = blaaa blaa blaaa irrelevant.. You have your own stuff here don't worry about it
    
       # here is the important part.. add a class Meta-
       class Meta:
          model = YourCustomUser #this is the "YourCustomUser" that you imported at the top of the file  
          fields = ('username', 'password1', 'password2', #etc etc, other fields you want displayed on the form)
    

    BIG NOTES, ATTENTION:

    1. This code worked for my case. I have a view for signing users up, I had a problem here and I solved it, I haven't tried it for logging in users.

    2. The include = () part is required, or you can add exclude = (), but you have to have one

提交回复
热议问题