Search code examples
djangodjango-modelsdjango-authentication

What is the model attached to django UserCreationForm()


I have read the official documentation for UserCreationForm(). I am trying to access the users I have created within other models. What model do I call to access the users I created within the UserCreationForm()? In short is their a default authentication model I can call to access the user model?


Solution

  • What model do I call to access the users I created within the UserCreationForm()?

    As we can see in the source code [GitHub], it uses the User model:

    from django.contrib.auth.models import User
    
    # …
    
    class UserCreationForm(forms.ModelForm):
    
        # …
    
        class Meta:
            model = User
            fields = ("username",)
            field_classes = {'username': UsernameField}
    
        # …

    You thus can import this model with:

    from django.contrib.auth.models import User

    The documentation on the User specifies the fields and methods defined on this model.