Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example with custom user model #18

Closed
maxwaiyaki opened this issue Mar 23, 2020 · 2 comments
Closed

Example with custom user model #18

maxwaiyaki opened this issue Mar 23, 2020 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@maxwaiyaki
Copy link

Is there an example with custom user model?

@PedroBern
Copy link
Owner

PedroBern commented Mar 23, 2020

Currently not, but it is easy, just do the following:

Fist, from Django docs:

Changing to a custom user model mid-project

Changing AUTH_USER_MODEL after you’ve created database tables is
significantly more difficult since it affects foreign keys and
many-to-many relationships, for example.

So, make sure to create the custom user model when you start your project.

Add the following to your custom user model

Following the Django custom user model.

from django.contrib.auth.models import AbstractUser

class CustomUser(AbstractUser):
    # ...
    USERNAME_FIELD = "<username_filed_name>" # e.g: "username", "email"
    EMAIL_FIELD = "<email_field_name>" # e.g: "email", "primary_email"

Add your custom user model in the settings

See here for more info.

# settings.py

AUTH_USER_MODEL = 'myapp.CustomUser'

Please let me know if you have further questions :)

@PedroBern PedroBern added the documentation Improvements or additions to documentation label Mar 23, 2020
@PedroBern PedroBern added this to TODO in Documentation Mar 23, 2020
@PedroBern
Copy link
Owner

Now the quickstart tutorial has a custom user model.

@PedroBern PedroBern moved this from TODO to Done in Documentation Mar 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
Documentation
  
Done
Development

No branches or pull requests

2 participants