A simple Django package that will aid you to switch from using the default Django Auth User model to a custom User model in an existing Django project.
Project description
django-bigtrill
django-bigtrill is a Django utility to help you migrate from the default Django User model to a custom user model in an existing project. It automates the process, making it safer and easier to switch without manual errors.
Features
- Detects and updates references to the default Django
Usermodel - Creates a new custom user model in an app with a name you choose
- Updates settings and migrations automatically
- Provides admin integration for the new user model
- Automatically creates backups of files before modification
- Allows you to restore files from backup with a flag
- Supports a dry run mode to preview changes without modifying files
Installation
pip install django-bigtrill
or clone into your project root directory:
git clone https://github.com/alexander-any7/django-bigtrill
Important: Your INSTALLED_APPS must be a list or this will not work.
Usage
-
Configure: Create a file named
bigtrill_settings.pyin the directory where you will run the start command. This file is required and must contain the following variables:PYTHON: Your Python command (e.g.,pythonorpython3)MANAGE_PY_FILE: Path to yourmanage.pyCOPY_MODEL: Desired name for your custom user modelNEW_AUTH_APP_LABEL: App label for the new user modelINSTALLED_APPS_SETTINGS_FILE_PATH: Absolute or relative path to your mainsettings.pyor where theINSTALLED_APPSis defined. (Relative paths will be converted automatically)AUTH_USER_MODEL_PATH: Absolute or relative path to where theAUTH_USER_MODELvariable is or will be definedDEFAULT_DJANGO_USER_MODEL_FILE_PATHS: List of files referencing the default user model (absolute or relative paths; optional)BASE_DIR: Absolute or relative path to your project root. You are advised to runpwdand provide the output of the command.GITIGNORE_PATH: Path to your.gitignorefile. This MUST be relative toBASE_DIR. The folders in the gitignore will not be searched for references to the defaultUsermodel.
Example:
# bigtrill_settings.py PYTHON = "python" MANAGE_PY_FILE = "manage.py" COPY_MODEL = "CustomUser" NEW_AUTH_APP_LABEL = "accounts" INSTALLED_APPS_SETTINGS_FILE_PATH = "<absolute or relative path to your settings.py>" AUTH_USER_MODEL_PATH = INSTALLED_APPS_SETTINGS_FILE_PATH FILES_TO_SEARCH = [] # absolute or relative paths BASE_DIR = "<absolute or relative path to your project root>" GITIGNORE_PATH = ".gitignore" # MUST BE RELATIVE to BASE_DIR
-
Run the start script:
If installed via pip:
bigtrill-start
or
python -m bigtrill.start
or
If cloned from git:
python django-bigtrill/bigtrill/start.pyFlags:
--dry_run: Show which files would be modified without making any changes.--restore: Restore files from backup and exit.--skip_pause: Skips the pause that allows you to check everything before proceeding to rename the model
Follow the prompts. The script will:
- Search for references to the default user model
- Create a new app and custom user model
- Update settings and run migrations
- Update imports and references
-
Review and test:
- Check your code and migrations
- Test your application thoroughly after using this.
Notes
-
Backup your project and database before running!
-
Do not run on production without testing.
-
After migration, update any manual references to the old user model.
-
Remove temporary files and update your main settings as needed.
- Remove temporary files (such as
bigtrill_temp_settings.py) and move any definitions from them (e.g.,AUTH_USER_MODEL) to your desired location in your mainsettings.pyfile to follow Django project conventions. - You might also want to remove the
bigtrill_settings.pyfile you created. - You might also want to remove
bigtrillfromINSTALLED_APPS. You can do this by going to the end of the file provided inINSTALLED_APPS_SETTINGS_FILE_PATHand there you will see:# Added by bigtrill.start INSTALLED_APPS += [..., 'bigtrill']
Simply remove bigtrill from the list. Optionally you can move the first item (the new app label where the new User model resides) to the actualINSTALLED_APPSlist or definition and remove this comment and the lines below all together.
- Remove temporary files (such as
-
Performance: Migration performance may vary depending on project size and number of users. For large datasets, consider running during low-traffic periods. Feel free to implement any optimization improvements you deem fit for your specific use case.
TODO
- Improve logging: Add detailed logging for each step of the migration process with proper stdout output to help users track progress and debug issues
- Improve model rename detection
Use a more robust method (e.g., analyzing the generated migration files) to confirm that Django has detected the rename.
License
MIT
Author
Alexander Anyaegbunam (alexander.any7@gmail.com)
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_bigtrill-2.0.2.tar.gz.
File metadata
- Download URL: django_bigtrill-2.0.2.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e672e5d34fbdf9ac69f7bd8a586fc0dd15cc589c0947416cd170f38cd5f59ff
|
|
| MD5 |
dff196e0ecd25fc784dbeb3e40528d64
|
|
| BLAKE2b-256 |
946bc7060eebf31c72899f30427c2473bd6e35731bc05e08fd631f906c52b07f
|
File details
Details for the file django_bigtrill-2.0.2-py3-none-any.whl.
File metadata
- Download URL: django_bigtrill-2.0.2-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
655cc845604ee6ee816fc0b52c6b587b6958fdb8435d7f42d2d0908033a2bbed
|
|
| MD5 |
099e16b0085f74ce39ba95e075310cd9
|
|
| BLAKE2b-256 |
85da5ea1d2e532aeb23e5600f70bb6bc9291394f2ad4f645cc8296d8f9ed88ed
|