Skip to main content

A more based base user model for Django.

Project description

A more based base user for Django.

django-based-user provides a clean minimal starting point for custom Django user models.

Why?

The Django authentication scheme provides for pluggable user models, and provides both an AbstractUser as well as a fairly vanilla User model.

The problem with these classes provided by the framework is that they are still too opinionated for my liking.

The primary issue is that the base implementation includes both a username and email field, and the username is required. For many projects, it makes sense to use the email address as the username. The base user model shipped with Django allows you to use email as the login field, but the username is still required. (Thumbs down.)

The secondary issue is that the base user model includes first_name and last_name fields. These fields are not required, so this is not a major issue, but it is annoying. You may want to use just a single name field, or you might choose to store the user's name in a separate Profile model or something like that. Or, you might choose to not even collect user's real names at all. I think that should be up to you.

See also: Falsehoods Programmers Believe About Names

The base user class provided by this package requires only an email and password, and then a few fields required for compatibility with the Django auth and admin packages, such as is_staff, is_superuser, groups, etc.

Requirements

  • Python 3.9+
  • Django 4.2+

django-based-user is a tiny package that, unfortunately, has to re-implement a few lines from django.contrib.auth.models. Take a look at based_user.models and you will see that this file started as a copy/paste of a couple of classes, and then removed a few fields and simplified a few methods accordingly.

The point is, this package follows the upstream code in django.contrib.auth.models closely, in order to provide a drop-in replacement for django.contrib.auth.models.AbstractUser. Current versions of Django will be supported, and unsupported/EOL versions will be officially unsupported. In reality, the relevant upstream code doesn't often change much, so other versions of Django will probably work just fine.

Installation

No surprises here. Install from PyPI using pip or equivalent:

pip install django-based-user

And that's it. No real need to add the package to INSTALLED_APPS, as there are no migrations or templates or static files to be collected.

B.Y.O.U. (Bring your own user)

Because Django makes it so easy to start with a custom user model, and so painful to switch to one later on, I think that a custom user model class is a clear example of PAGNI (Probably Are Gonna Need It). For that reason, this package provides only an abstract base user class, and an associated model manager class. You have to inherit the base class into your own custom model, but it can be as simple as this:

from based_user.models import BasedUser

class User(BasedUser):
    pass

License

Distributed under the MIT license. See LICENSE for more information.

Contributing

The point of this package is to provide a minimal, unopinionated baseline for custom Django user model implementations. As such, the scope will remain necessarily constrained. Don't expect much to be added in terms of bells and whistles, as those tend to be opinionated. That said, bug fixes and other improvements are welcome. Follow the usual process:

  1. Fork the project
  2. Create your own feature branch (git checkout -b feature/foobar)
  3. Commit you changes (git commit -am "Add more foobar")
  4. Push to the branch (git push origin feature/foobar)
  5. Create a new Pull Request

Code of Conduct

You have heard of the Golden Rule. Taleb's Silver Rule is more robust. "Do not treat others the way you would not like them to treat you."

Based?

The name is a joke. Wordplay makes me smile. All is well.

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_based_user-0.1.3.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_based_user-0.1.3-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file django_based_user-0.1.3.tar.gz.

File metadata

  • Download URL: django_based_user-0.1.3.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.1 Darwin/23.5.0

File hashes

Hashes for django_based_user-0.1.3.tar.gz
Algorithm Hash digest
SHA256 7d2e1a7c0febf9996afe63860b7dfb0bb9fef3fa19ece7600ad8599cb6334ead
MD5 395a02da3cabbf8fa50f2e39e8266b54
BLAKE2b-256 5726fcf3a9c0632ca028c50ffee8e4493fb34d7022baae2159b79a6bee46fd5e

See more details on using hashes here.

File details

Details for the file django_based_user-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: django_based_user-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.1 Darwin/23.5.0

File hashes

Hashes for django_based_user-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b69317ed4397998918be3d867bf8ee35601577680ac61d25b5227be003bd7a73
MD5 3eb157fd2463769209b58d42ac4ac1b3
BLAKE2b-256 3b50e286fba9c11df997f89ea717b759b1e2de4cd2218943cff30c453dd67f16

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page