Organize Django admin sections/models without additional apps
Project description
░▒▓███████▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓████████▓▒░▒▓█▓▒░ ░▒▓████████▓▒░
░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░
░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░
░▒▓██████▓▒░░▒▓████████▓▒░▒▓██████▓▒░ ░▒▓█▓▒░ ░▒▓██████▓▒░
░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░
░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░
░▒▓███████▓▒░░▒▓█▓▒░░▒▓█▓▒░▒▓████████▓▒░▒▓████████▓▒░▒▓█▓▒░
Who?
Django Shelf is meant to be a simple way to categorize your model admins instead of relying on creating new apps for each category.
Bu... but why?
The main reason is simply to avoid creating new apps for each category of model admins. This is especially useful if you got legacy applications that will break if you try to split them into new apps.
Yes, I know that this is not the best practice, but sometimes you just need to do it.
How do I use it?
- Install the package using
pip install django-admin-shelf. - Add
admin_shelfto yourINSTALLED_APPSin your Django settings. - Create categories in your
admin.pyfile as follows:
from admin_shelf.admin import Category
from example.models import Model1
custom_category = Category(name="Custom Category")
@custom_category.register(Model1)
class Model1Admin(admin.ModelAdmin):
pass
A little piece of documentation
The admin_shelf.admin.Category class is used to create categories for your model admins. You can register your model admins to these categories using the @category.register(Model) decorator.
You can set a order for both the categories and the model admins by passing an order argument to the Category class and the @register decorator, respectively.
Example:
from admin_shelf.admin import Category
from example.models import Model1, Model2
custom_category = Category(name="Custom Category", order=1)
@custom_category.register(Model1, order=2)
class Model1Admin(admin.ModelAdmin):
pass
@custom_category.register(Model2, order=1)
class Model2Admin(admin.ModelAdmin):
pass
Yes, it is just that simple. You can also use the @register decorator without passing a category, in which case it will be registered to the default category. Or use the default register from django admin if you want to register your model admin without a category.
Before shelf:
After shelf:
Translation support
Category(name=...) accepts both plain strings and Django's lazy translation
proxies. To localize a category, pass a gettext_lazy value:
from django.utils.translation import gettext_lazy as _
from admin_shelf.admin import Category
shop_category = Category(name=_("Shop"))
@shop_category.register(Product)
class ProductAdmin(admin.ModelAdmin):
pass
The name is resolved against the active language on every request, so users switching languages see the category label update accordingly.
Recommendation: define each Category once and reuse the same instance
across @register calls. Categories are deduplicated by the identity of the
name value; two lazy proxies built from the same source string are distinct
Python objects and would create separate buckets.
Anything else?
Running the example app
To run the example app, you can use the following commands:
# You need to have docker installed
docker compose up example
Running the tests
To run the tests, you can use the following commands:
# You need to have docker installed
docker compose up test
How do I contribute?
If you want to contribute to this project, you can do so by creating an issue! And if you want to contribute with code, you can fork the repository and create a pull request.
Check the CONTRIBUTING.md file for more information on how to contribute.
Is it true that bananas are radioactive?
Yes.
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_admin_shelf-0.2.2.tar.gz.
File metadata
- Download URL: django_admin_shelf-0.2.2.tar.gz
- Upload date:
- Size: 23.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3f5cd20eef3e2c582d416d33a3c116eaca77b836cc67459fa8f4e9cfab411ff9
|
|
| MD5 |
a78f08af36f6829e6a94ac88c1b9ed4c
|
|
| BLAKE2b-256 |
c181bedb035473ab8afa66a93a52dc308083d22016af9e3521b4b258d29a1063
|
Provenance
The following attestation bundles were made for django_admin_shelf-0.2.2.tar.gz:
Publisher:
release.yaml on niltonfrederico/django-shelf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_admin_shelf-0.2.2.tar.gz -
Subject digest:
3f5cd20eef3e2c582d416d33a3c116eaca77b836cc67459fa8f4e9cfab411ff9 - Sigstore transparency entry: 1672838729
- Sigstore integration time:
-
Permalink:
niltonfrederico/django-shelf@040feb6ac39cfb638ae233fc006ba738f77586bf -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/niltonfrederico
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@040feb6ac39cfb638ae233fc006ba738f77586bf -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_admin_shelf-0.2.2-py3-none-any.whl.
File metadata
- Download URL: django_admin_shelf-0.2.2-py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90397cf0b1e9b65ae44af41d7ccad68c41e7ac5df7e3664842075a9b5b011781
|
|
| MD5 |
0583e659ccc78e34649c5e336b5e74e2
|
|
| BLAKE2b-256 |
1b2e511eb8d7fb64ffd2e7e0eae0c72f67ac3127cb65eb10bb4392a1a4d6754b
|
Provenance
The following attestation bundles were made for django_admin_shelf-0.2.2-py3-none-any.whl:
Publisher:
release.yaml on niltonfrederico/django-shelf
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_admin_shelf-0.2.2-py3-none-any.whl -
Subject digest:
90397cf0b1e9b65ae44af41d7ccad68c41e7ac5df7e3664842075a9b5b011781 - Sigstore transparency entry: 1672838758
- Sigstore integration time:
-
Permalink:
niltonfrederico/django-shelf@040feb6ac39cfb638ae233fc006ba738f77586bf -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/niltonfrederico
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@040feb6ac39cfb638ae233fc006ba738f77586bf -
Trigger Event:
push
-
Statement type: