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. Set django_modern_user.ModernUser as your user model:

    AUTH_USER_MODEL = "django_modern_user.ModernUser"
    
  4. To use the provided ModernUserAdmin class in your Django admin site, import ModernUserAdmin and ModernUser from django_modern_user in your admin.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)
    
  5. 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


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.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

django_modern_user-0.2.1-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_modern_user-0.2.1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.4 Linux/5.15.90.1-microsoft-standard-WSL2

File hashes

Hashes for django_modern_user-0.2.1.tar.gz
Algorithm Hash digest
SHA256 6d00b8881f2229990d32cc276e1a0530f6c7d713a6f188ace305360e08f4e0d1
MD5 08f02b614d6f2aba8a8584949663807f
BLAKE2b-256 d3e2bd3a578cdb68d7fee65d34b4766c38454de416b1a5212e3bd5c62500002a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_modern_user-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.4 Linux/5.15.90.1-microsoft-standard-WSL2

File hashes

Hashes for django_modern_user-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 142e99ba775391b647d6a6daa710ce5c25b4b1c81b93de7262df34bf2bfd1b8f
MD5 0f26f75760c509b2300521f201e64b11
BLAKE2b-256 409ca177971eef73b5561c0ee942a71edfcda29484a887ea5bc6c18c2f50cee5

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