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

Uploaded Source

Built Distribution

django_modern_user-0.2.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_modern_user-0.2.0.tar.gz
  • Upload date:
  • Size: 6.6 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.0.tar.gz
Algorithm Hash digest
SHA256 196ac2c8057c7794cd580959cb18e50c2bba2ce5430c1a645af086c027218e45
MD5 069663ea489c478b9b076af82d8556f3
BLAKE2b-256 8939a7d70a69c285951c434e69c37ed63fa9db9c70cd73dabf6597dd1d34f174

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_modern_user-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8e3ca89b450e1a80f22d0944b5ccac1847dacfb2afb4219787ad97cad36ecc24
MD5 733bea47e4b9e68af101a017e6244975
BLAKE2b-256 f57fa227569e0cdca4837037ee1b1efaef72c64883c97619f0be2f16cc6b17de

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