|
| 1 | +# Getting started with django-admin-contexts |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +[](https://pypi.python.org/pypi/django-admin-contexts) |
| 6 | + |
| 7 | +[](https://codecov.io/gh/matagus/django-admin-contexts) |
| 8 | +[](https://opensource.org/licenses/BSD-3-Clause) |
| 9 | + |
| 10 | +Display only a set of apps and models in the Django Admin homepage, based on the chosen context. This is useful when |
| 11 | +you have a lot of apps and models and you want to focus on a specific set of them. |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | +## Installation |
| 16 | + |
| 17 | +Via `pip` command: |
| 18 | + |
| 19 | +```bash |
| 20 | +pip install django-admin-contexts |
| 21 | +``` |
| 22 | + |
| 23 | +...or you can clone the repo and install it using `pip` too: |
| 24 | + |
| 25 | +```bash |
| 26 | +git clone git://github.com/matagus/django-admin-contexts.git |
| 27 | +cd django-admin-contexts |
| 28 | +pip install -e . |
| 29 | +``` |
| 30 | + |
| 31 | +## Quick Start |
| 32 | + |
| 33 | +Add `django_admin_contexts` to your `INSTALLED_APPS` in `settings.py` **before** `django.contrib.admin`: |
| 34 | + |
| 35 | +```python |
| 36 | +INSTALLED_APPS = ( |
| 37 | + # ... |
| 38 | + "django_admin_contexts", |
| 39 | + # ... |
| 40 | + "django.contrib.admin", |
| 41 | + # ... |
| 42 | +) |
| 43 | +``` |
| 44 | + |
| 45 | +Then run the migrations: |
| 46 | + |
| 47 | +```bash |
| 48 | +python manage.py migrate |
| 49 | +``` |
| 50 | + |
| 51 | +## Usage |
| 52 | + |
| 53 | +Browse to the Django Admin and create some contexts in the "Django Admin Contexts" section, associating them with one |
| 54 | +or more models. |
| 55 | + |
| 56 | +Then, you can see the contexts in the Django Admin homepage. |
| 57 | + |
| 58 | +## Running Tests |
| 59 | + |
| 60 | +**Prerequisites:** Install Hatch if not already installed: `pip install hatch` |
| 61 | + |
| 62 | +**List available test environments:** |
| 63 | +```bash |
| 64 | +hatch env show test |
| 65 | +``` |
| 66 | + |
| 67 | +**Run all tests (all Python + Django combinations):** |
| 68 | +```bash |
| 69 | +hatch run test:test |
| 70 | +``` |
| 71 | + |
| 72 | +**Run tests for specific Python/Django version:** |
| 73 | +```bash |
| 74 | +hatch run test.py3.14-5.2:test # Python 3.14 + Django 5.2 |
| 75 | +hatch run test.py3.12-5.1:test # Python 3.12 + Django 5.1 |
| 76 | +``` |
| 77 | + |
| 78 | +**Run specific test file:** |
| 79 | +```bash |
| 80 | +hatch run test.py3.12-5.2:test tests.test_models |
| 81 | +``` |
| 82 | + |
| 83 | +**Coverage:** |
| 84 | +```bash |
| 85 | +hatch run test:cov # Run tests with coverage report |
| 86 | +``` |
| 87 | + |
| 88 | +**Troubleshooting:** If you encounter environment issues, clean and rebuild: `hatch env prune` |
0 commit comments