Skip to main content

Organize Django admin sections/models without additional apps

Project description

codecov pip

 ░▒▓███████▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓████████▓▒░▒▓█▓▒░      ░▒▓████████▓▒░
░▒▓█▓▒░      ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░      ░▒▓█▓▒░      ░▒▓█▓▒░
░▒▓█▓▒░      ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░      ░▒▓█▓▒░      ░▒▓█▓▒░
 ░▒▓██████▓▒░░▒▓████████▓▒░▒▓██████▓▒░ ░▒▓█▓▒░      ░▒▓██████▓▒░
       ░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░      ░▒▓█▓▒░      ░▒▓█▓▒░
       ░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░      ░▒▓█▓▒░      ░▒▓█▓▒░
░▒▓███████▓▒░░▒▓█▓▒░░▒▓█▓▒░▒▓████████▓▒░▒▓████████▓▒░▒▓█▓▒░

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?

  1. Install the package using pip install django-admin-shelf.
  2. Add admin_shelf to your INSTALLED_APPS in your Django settings.
  3. Create categories in your admin.py file 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.

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

django_admin_shelf-0.1.0.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

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

django_admin_shelf-0.1.0-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file django_admin_shelf-0.1.0.tar.gz.

File metadata

  • Download URL: django_admin_shelf-0.1.0.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.5 Darwin/24.5.0

File hashes

Hashes for django_admin_shelf-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b2a511c431ada26a4dacce835d48bfe94444d6243e038c7a3ed4f1d8170c5d79
MD5 145913c3ff56654b57056281c1c6e53d
BLAKE2b-256 50e08f016fb628e90af48ddf8afddd4613200cf96e489dd43753606ac90645b6

See more details on using hashes here.

File details

Details for the file django_admin_shelf-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_admin_shelf-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.5 Darwin/24.5.0

File hashes

Hashes for django_admin_shelf-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 de83f4e27dae4edeb1aeb3959fb0bfc8bc4f35013c26fabda444edc617f151e6
MD5 fd3fe14b888b1b2d38ee275fe3f8c7ea
BLAKE2b-256 276b04c42bbeb87623e9e016a338cc0ff61ff851266e9e7c50bba25b88d8a6b9

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