django-simple-user

Provides an abstract base User model without first and last name fields.


Keywords
django-simple-user
License
BSD-3-Clause
Install
pip install django-simple-user==0.1.2

Documentation

Django Simple User

Updates https://travis-ci.org/valerymelou/django-simple-user.svg?branch=master

Provides a simple abstract User model without first and last name fields.

Documentation

The full documentation is available at https://django-simple-user.readthedocs.io.

Quickstart

Install Django Simple User:

pip install django-simple-user

Features

  • Abstract User model without the fields first_name and last_name
  • Abstract User model without the fields first_name, last_name and email
  • Abstract User model without the fields first_name, last_name and username

Usage

If you are like me, you might have found yourself extending django.contrib.auth.base_user.AbstractBaseUser just to remove the first_name and last_name fields from your final User model. I was tired of doing that and I created this package. It defines an abstract User model without those fields so that you can just inherit from it to create your User model. Let's suppose you have a users app with a models.py file containing the following:

from simple_user.models import AbstractUser


class User(AbstractUser):
    pass

Then in your settings file:

AUTH_USER_MODEL = 'users.User'

This will create a User model with all the fields that happen to exists in the default Django's User model except first_name and last_name and use it for authentication in your app.

Bonuses

There are some cases where you only want username or email but not both fields in your model. Django Simple User has got you covered. You can use SimpleUserWithUsername or SimpleUserWithEmail to achieve each scenario.

For a User model with username as identifying field but without first_name, last_name and email do:

from simple_user.models import SimpleUserWithUsername


class User(SimpleUserWithUsername):
    pass

For a User model with email as identifying field but without first_name, last_name and username do:

from simple_user.models import SimpleUserWithUsername


class User(SimpleUserWithEmail):
    pass

Note

Always remember to set your extended User model as the authentication User model by setting AUTH_USER_MODEL in your settings file.

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

Credits

Tools used in rendering this package: