Skip to main content

Custom User Model

Project description

Eazy Django User

Eazy Django User is a django package that provides a user model with user email as the identifier.

Installation

Use the package manager pip to install foobar.

pip install eazy-django-user

Usage

  1. Add "eazy_user" to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [
        ...
        'eazy_user',
    ]
  1. set AUTH_USER_MODEL in setting.py to "eazy_user.EmailUser" like this: Note: Add this setting before initial migration else there will be clashes with the default user model.
AUTH_USER_MODEL = 'eazy_user.EmailUser'
  1. Run python manage.py migrate to apply the migrations to the database.
python manage.py migrate
  1. You can access the user foreign key like this:
from django.conf import settings

User = settings.AUTH_USER_MODEL

class YourModel(models.Model):
     user = models.ForeignKey(User, on_delete=models.CASCADE)
  1. Or by using the get_user_model method.
from django.contrib.auth import get_user_model

User = get_user_model()

But you would most likely want to extend the python EmailUser model you can do that easily:

from eazy_user.models import EmailUser

class YourCustomUser(EmailUser):
    ....

Whatever you choose, make sure to set the resulting user model as the python AUTH_USER_MODEL in the settings.py file

AUTH_USER_MODEL = '<your_app_name>.<YourCustomUser>' """<your_app_name> refers to the app that contains your custom user model, while <YourCustomUser> is the custom user model."""

Now you can proceed to creating a super user bash python manage.py createsuperuser like you normaly would, and enjoy :)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

eazy-django-user-1.1.1.tar.gz (4.5 kB view hashes)

Uploaded Source

Built Distribution

eazy_django_user-1.1.1-py3-none-any.whl (5.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page