An improved custom user model for django projects
Project description
Django Modern User
Django Modern User is a custom user model for Django projects that replaces the default username
field with a case-insensitive email
field for authentication, and removes the requirement for first and last names. This model aims to provide a more practical and modern approach to user management in Django.
Installation
[!IMPORTANT] The instructions below are intended for integrating
django-modern-user
into new projects. Incorporating this package into existing projects, especially those with existing user data, can be complex and requires careful database migrations and potentially some code adjustments. The integration into projects with existing users is beyond the scope of this documentation.
-
Install
django-modern-user
via pip:python -m pip install django-modern-user
-
Add
django_modern_user
to yourINSTALLED_APPS
in your Django settings:INSTALLED_APPS = [ # ... other apps 'django_modern_user', ]
-
Set
django_modern_user.ModernUser
as your user model:AUTH_USER_MODEL = "django_modern_user.ModernUser"
-
To use the provided
ModernUserAdmin
class in your Django admin site, importModernUserAdmin
andModernUser
fromdjango_modern_user
in youradmin.py
file:from django_modern_user.admin import ModernUserAdmin from django_modern_user.models import ModernUser from django.contrib import admin admin.site.register(ModernUser, ModernUserAdmin)
-
Run migrations to create the necessary database table:
python manage.py migrate
Usage
With django-modern-user
, authentication is done using the email field. The email field is case-insensitive, ensuring a user-friendly authentication process.
Here's an example of how you might create a new user:
from django_modern_user.models import ModernUser
# Create a new user
user = ModernUser.objects.create_user(email='example@example.com', password='password123')
# Create a superuser
superuser = ModernUser.objects.create_superuser(email='admin@example.com', password='password123')
Custom User Manager
django-modern-user
comes with a custom user manager, UserPlusManager
, which handles user creation and ensures the email field is used for authentication.
Further Customization
You can further customize the ModernUser
model and UserPlusManager
to meet the specific needs of your project.
Contributing
Feel free to fork the project, open a PR, or submit an issue if you find bugs or have suggestions for improvements.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django_modern_user-0.2.3.tar.gz
.
File metadata
- Download URL: django_modern_user-0.2.3.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d35da4b34843e695856759c7bee981e945a1e68f083905489eb89bb48b3da68 |
|
MD5 | bcc70721c1646c32b099f62e3090c7f6 |
|
BLAKE2b-256 | 09055d04bed83b2f31e45cbf2196c76c8a89cb6b4399db933e5287dda633fd68 |
File details
Details for the file django_modern_user-0.2.3-py3-none-any.whl
.
File metadata
- Download URL: django_modern_user-0.2.3-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca24d998231f65c1ff25129bde5ae04227c48ca7fedfb144aadda9290b63fd99 |
|
MD5 | d17a4a1e33d4d42441c59d7c4ceb6f13 |
|
BLAKE2b-256 | 0798fd4f4fbb778cf7eb2702ce48f39c70eff92b21bf8f71261906a18a18192b |