Django-Swap-User (Beta)
About
If you are tired from copying one custom user model from one project to another ones - use this package. This will do all for you.
Installation
pip install django-swap-user
Basic usage
- Choose one of models that suits for you and copy related settings from the table:
| Application name | Username field | Description | INSTALLED_APPS |
AUTH_USER_MODEL |
Replace django.contrib.admin to |
|---|---|---|---|---|---|
to_email |
email |
User with email username |
"swap_user", "swap_user.to_email", |
"swap_to_email.EmailUser" |
not required |
to_email_otp |
email |
User with email username, without password and OPT authentication |
"swap_user", "swap_user.to_email_otp", |
"swap_to_email_otp.EmailOTPUser" |
"swap_user.to_email_otp.apps.SiteConfig" |
to_phone |
phone |
User with phone username |
"swap_user", "swap_user.to_phone", |
"swap_to_phone.PhoneUser" |
not required |
to_phone_otp |
phone |
User with phone username, without password and OTP authentication |
"swap_user", "swap_user.to_phone_otp", |
"swap_to_phone_otp.PhoneOTPUser" |
"swap_user.to_phone_otp.apps.SiteConfig" |
- Add corresponding app to
INSTALLED_APPS:
INSTALLED_APPS = [
...
"swap_user",
"swap_user.to_email",
...
]
- Change
AUTH_USER_MODELto corresponding:
AUTH_USER_MODEL = "swap_to_email.EmailUser"
-
If required replace
django.contrib.admininINSTALLED_APPSto something. -
Apply migrations:
python manage.py migrate swap_to_email
Architecture
Application swap_user split into 3 apps:
to_email- provides user withemailusername fieldto_email_otp- provides user withemailusername field and OTP (One Time Password) authenticationto_phone- provides user withphoneusername fieldto_phone_otp- provides user withphoneusername field and OTP (One Time Password) authentication
Why so unusual architecture?
Because if we leave them in one app, they all will create migrations and tables - such approach leads us to redundant tables. They will be treated as 3 custom models within the same app, which causes perplexing and cognitive burden.
With such approach (when there is a common app which contains internal apps) - the user choose and connect only the specific user model which suits best for concrete business-logic.
I have found such approach at Django REST Framework authtoken application and decide to use it - reference is here.
Providing User model at start of project
When you are starting a project from zero or scratch - this is a best moment to provide custom User model. Because you have't a lot of migrations or you can easily regenerate them. Moreover, Django's official docs recommend to provide custom User model even if you are fully satisfied with default one - in future it will be easier to extend custom model that fits into your business cases.
Providing User model at mid of project
This is a harder way of doing things, but it is still possible to do:
- Do all the steps at testing database and ONLY IF all of them was successful - try to apply at production environment
- Please note that these steps are common - they fit in most cases, but in some circumstances you need act on situation.
- Create a backup of your database
- Add stable tag into your repository or save a commit hash reference
- Pray to the heavens
- Remove all of yours migrations in every app of Django's project
- Remove all records from
django_migrationstable, for example with SQLTRUNCATE django_migrations - Now we have a "clean" state, so we can change default model
- Generate new migrations for all of your applications -
python manage.py makemigrations - Now we need to fake migrate because we already have all the tables with data
- First fake the
authapplication because we are depending from this one -python manage.py migrate --fake auth - Install this library, follow instructions and apply migrations
- Then fake rest of migrations we have -
python manage.py migrate --fake - Run your application!
Metadata
Release files for django-swap-user 0.9.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-swap-user-0.9.8.tar.gz | 20.9 kB | Without provenance | Details for django-swap-user-0.9.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_swap_user-0.9.8-py3-none-any.whl | Python 3 | none | any | Details for django_swap_user-0.9.8-py3-none-any.whl |
Total release size: 57.9 kB
Release files / django-swap-user-0.9.8.tar.gz
| Download URL | django-swap-user-0.9.8.tar.gz |
|---|---|
| Size | 20.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
998ca28b2c68fac2756bbfe2bd72b30ef311f8057593446c8e7d3d4bdd5c1919
|
|
BLAKE2b-256 checksum How to use checksums |
a65b0465127e43c62fbd20d3b4ae94804b50af0a7526fcb474b2439927dabc03
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.12 CPython/3.7.7 Darwin/19.6.0
|
Release files / django_swap_user-0.9.8-py3-none-any.whl
| Download URL | django_swap_user-0.9.8-py3-none-any.whl |
|---|---|
| Size | 37.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
07f2545a0786e8ff6e434bb41e9d86dff6597a086c40cc3ac933491ed6048077
|
|
BLAKE2b-256 checksum How to use checksums |
b9c4d105bb6c1643764e4684be950b5754c7e3a5df5797a30c8a816dc3c03f09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.12 CPython/3.7.7 Darwin/19.6.0
|
Security for django-swap-user 0.9.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.