Skip to main content

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.

  1. Install django-modern-user via pip:

    python -m pip install django-modern-user
    
  2. Add django_modern_user to your INSTALLED_APPS in your Django settings:

    INSTALLED_APPS = [
        # ... other apps
        'django_modern_user',
    ]
    
  3. Create a new user model in your project by subclassing django_modern_user.ModernUser:

    # In your models.py
    from django_modern_user.models import ModernUser
    
    class CustomUser(ModernUser):
        pass
    
  4. Update your Django settings to use your new user model:

    AUTH_USER_MODEL = "<your_app_name>.CustomUser"
    
  5. To use the provided ModernUserAdmin class in your Django admin site, you can subclass it in your admin.py file:

    from django.contrib import admin
    from django_modern_user.admin import ModernUserAdmin
    from .models import CustomUser
    
    @admin.register(CustomUser)
    class YourUserAdmin(ModernUserAdmin):
        pass
    
  6. Run migrations to create the necessary database table:

    python manage.py migrate
    

This setup allows you to further customize your user model and admin interface while benefiting from the features provided by django-modern-user.

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.

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


Download files

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

Source Distribution

django_modern_user-0.2.7.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

django_modern_user-0.2.7-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file django_modern_user-0.2.7.tar.gz.

File metadata

  • Download URL: django_modern_user-0.2.7.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for django_modern_user-0.2.7.tar.gz
Algorithm Hash digest
SHA256 096a47c415c7b96c259f4bdfd8147b973c58e3368da9f2bc7db2057fe2aeea8f
MD5 f5eafced39b31af977ef4c8b04fee18d
BLAKE2b-256 dc3ef3305ca9cf5c59c67b9009ef7e00d0233db58aa637a335d2f14b1ff2ea6d

See more details on using hashes here.

File details

Details for the file django_modern_user-0.2.7-py3-none-any.whl.

File metadata

File hashes

Hashes for django_modern_user-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 8a90b4600f57b24242d7f6c890d96918793e8a3d40c8f1fe24cb204e9ed47072
MD5 394680c28456d99000d4e3a589f1fa52
BLAKE2b-256 1b46f58ecc4873d48df9e2ed1c9a526db70d53480325454e6b079a53aabbe03b

See more details on using hashes here.

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