django-custom-admin-pages


Namedjango-custom-admin-pages JSON
Version 1.2.4 PyPI version JSON
download
home_pagehttps://github.com/lekjos/django-custom-admin-pages
SummaryA django app that lets you add standard class-based views to the django admin index and navigation.
upload_time2023-11-12 18:09:47
maintainerLeif Kjos
docs_urlNone
authorLeif Kjos
requires_python>=3.8,<4.0
licenseBSD-3-Clause
keywords django admin django-admin django admin interface customize admin custom admin customize
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![PyPI](https://img.shields.io/pypi/v/django-custom-admin-pages)](https://pypi.org/project/django-custom-admin-pages/)
![Python Supported](https://img.shields.io/badge/Python-_3.8,_3.9,_3.10,_3.11,_3.12-blue)
![Django Supported](https://img.shields.io/badge/Django-3.2,_4.0,_4.1,_4.2-blue)
[![Tests](https://github.com/lekjos/django-custom-admin-pages/actions/workflows/build_and_test.yml/badge.svg)](https://github.com/lekjos/django-custom-admin-pages/actions/workflows/build_and_test.yml)
[![Docs](https://readthedocs.org/projects/django-custom-admin-pages/badge/?version=latest)](https://django-custom-admin-pages.readthedocs.io/en/latest/?badge=latest)
[![CodeCov](https://codecov.io/gh/lekjos/django-custom-admin-pages/branch/master/graph/badge.svg?token=AJG2WICKXA)](https://codecov.io/gh/lekjos/django-custom-admin-pages)
![PyPI - Downloads](https://img.shields.io/pypi/dm/django-custom-admin-pages)


# Django Custom Admin Pages
A django app that lets you add standard class-based views to the django admin index and navigation. Create a view, register it like you would a ModelAdmin, and it appears in the Django Admin Nav.

![Example View](docs/source/static/example_view.png)

Check out the [full documentation](https://django-custom-admin-pages.readthedocs.io) for more in-depth information.


## Quick Start

1. Install the app from pypi `pip install django_custom_admin_pages`
2. Remove `django.contrib.admin` from your installed apps
3. In your django settings file add the following lines to your `INSTALLED_APPS``:

```python
INSTALLED_APPS = [
   # "django.contrib.admin", #REMOVE THIS LINE
   # ...
   "django_custom_admin_pages",
   "django_custom_admin_pages.admin.CustomAdminConfig"
   # ...
]
```

## Usage

To create a new custom admin view:

1. Create a class-based view in `django_custom_admin_pages.views` which inherits from `custom_admin.views.admin_base_view.AdminBaseView`.
2. Set the view class attribute `view_name` to whatever name you want displayed in the admin index.
3. Register the view similar to how you would register a ModelAdmin using a custom admin function: `admin.site.register_view(YourView)`.
4. Use the template `django_custom_admin_pages.templates.base_custom_admin.html` as a sample for how to extend the admin templates so that your view has the admin nav.


Also see `test_proj.test_app.views.example_view.py`

_Example:_

```python
## in django_custom_admin_pages.views.your_special_view.py
from django.contrib import admin
from django.views.generic import TemplateView
from django_custom_admin_pages.views.admin_base_view import AdminBaseView

class YourCustomView(AdminBaseView, TemplateView):
   view_name="My Super Special View"
   template_name="my_template.html"
   route_name="some-custom-route-name" # if omitted defaults to snake_case of view_name
   app_label="my_app" # if omitted defaults to "django_custom_admin_pages". Must match app in settings

   # always call super() on get_context_data and use it to start your context dict.
   # the context required to render admin nav-bar is included here.
   def get_context_data(self, *args, **kwargs):
      context:dict = super().get_context_data(*args, **kwargs)
      # add your context ...
      return context

admin.site.register_view(YourCustomView)
```

Your template should extend `admin/base.html` or `base_custom_admin.html` template:
```html
<!-- my_template.html -->
{% extends 'base_custom_admin.html' with title="your page title" %} 
{% block content %}
<h1>Hello World</h1>
{% endblock %}
```

### Important: Custom Views Must Be Registered Before Admin URLs are Loaded

Be sure to import the files where your views are stored prior to loading your root url conf. For example:

```python
# project/urls.py
from django.contrib import admin

# importing view before url_patterns ensures it's registered!
from some_app.views import YourCustomView 

url_patterns = [
   path("admin/", admin.site.urls),
   ...
]
```

## Configurable Settings

- `CUSTOM_ADMIN_DEFAULT_APP_LABEL`: set to override the default app_label (default: `django_custom_admin_pages`)

## Contributing

Reach out to the author if you'd like to contribute! Also free to file bug reports or feature requests via [github issues](https://github.com/lekjos/django-custom-admin-pages/issues).

### Local Development

To start the test_project:
- `cd <repo_root>`
- `poetry install --with dev`
- `python test_proj/manage.py migrate`
- `python test_proj/manage.py createsuperuser` (follow prompts)
- `python test_proj/manage.py runserver`
- Navigate too `localhost:8000/admin`, log in, and there should be one custom admin view.

To run the test suite:
- `poetry run pytest`

Prior to committing:
1. Run pylint:
   - `cd <repo_root>`
   - `poetry run pylint django_custom_admin_pages/`

2. Run black:
   - `poetry run black .`

2. Run isort:
   - `poetry run isort django_custom_admin_pages/`

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/lekjos/django-custom-admin-pages",
    "name": "django-custom-admin-pages",
    "maintainer": "Leif Kjos",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "leif+pypi@leifkjos.com",
    "keywords": "django,admin,django-admin,django admin,interface,customize admin,custom admin,customize",
    "author": "Leif Kjos",
    "author_email": "leif+pypi@leifkjos.com",
    "download_url": "https://files.pythonhosted.org/packages/70/04/8cb217f57218b2ae0b4ec382d174f46e2539b437686b4d21f6370dbd850c/django_custom_admin_pages-1.2.4.tar.gz",
    "platform": null,
    "description": "[![PyPI](https://img.shields.io/pypi/v/django-custom-admin-pages)](https://pypi.org/project/django-custom-admin-pages/)\n![Python Supported](https://img.shields.io/badge/Python-_3.8,_3.9,_3.10,_3.11,_3.12-blue)\n![Django Supported](https://img.shields.io/badge/Django-3.2,_4.0,_4.1,_4.2-blue)\n[![Tests](https://github.com/lekjos/django-custom-admin-pages/actions/workflows/build_and_test.yml/badge.svg)](https://github.com/lekjos/django-custom-admin-pages/actions/workflows/build_and_test.yml)\n[![Docs](https://readthedocs.org/projects/django-custom-admin-pages/badge/?version=latest)](https://django-custom-admin-pages.readthedocs.io/en/latest/?badge=latest)\n[![CodeCov](https://codecov.io/gh/lekjos/django-custom-admin-pages/branch/master/graph/badge.svg?token=AJG2WICKXA)](https://codecov.io/gh/lekjos/django-custom-admin-pages)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/django-custom-admin-pages)\n\n\n# Django Custom Admin Pages\nA django app that lets you add standard class-based views to the django admin index and navigation. Create a view, register it like you would a ModelAdmin, and it appears in the Django Admin Nav.\n\n![Example View](docs/source/static/example_view.png)\n\nCheck out the [full documentation](https://django-custom-admin-pages.readthedocs.io) for more in-depth information.\n\n\n## Quick Start\n\n1. Install the app from pypi `pip install django_custom_admin_pages`\n2. Remove `django.contrib.admin` from your installed apps\n3. In your django settings file add the following lines to your `INSTALLED_APPS``:\n\n```python\nINSTALLED_APPS = [\n   # \"django.contrib.admin\", #REMOVE THIS LINE\n   # ...\n   \"django_custom_admin_pages\",\n   \"django_custom_admin_pages.admin.CustomAdminConfig\"\n   # ...\n]\n```\n\n## Usage\n\nTo create a new custom admin view:\n\n1. Create a class-based view in `django_custom_admin_pages.views` which inherits from `custom_admin.views.admin_base_view.AdminBaseView`.\n2. Set the view class attribute `view_name` to whatever name you want displayed in the admin index.\n3. Register the view similar to how you would register a ModelAdmin using a custom admin function: `admin.site.register_view(YourView)`.\n4. Use the template `django_custom_admin_pages.templates.base_custom_admin.html` as a sample for how to extend the admin templates so that your view has the admin nav.\n\n\nAlso see `test_proj.test_app.views.example_view.py`\n\n_Example:_\n\n```python\n## in django_custom_admin_pages.views.your_special_view.py\nfrom django.contrib import admin\nfrom django.views.generic import TemplateView\nfrom django_custom_admin_pages.views.admin_base_view import AdminBaseView\n\nclass YourCustomView(AdminBaseView, TemplateView):\n   view_name=\"My Super Special View\"\n   template_name=\"my_template.html\"\n   route_name=\"some-custom-route-name\" # if omitted defaults to snake_case of view_name\n   app_label=\"my_app\" # if omitted defaults to \"django_custom_admin_pages\". Must match app in settings\n\n   # always call super() on get_context_data and use it to start your context dict.\n   # the context required to render admin nav-bar is included here.\n   def get_context_data(self, *args, **kwargs):\n      context:dict = super().get_context_data(*args, **kwargs)\n      # add your context ...\n      return context\n\nadmin.site.register_view(YourCustomView)\n```\n\nYour template should extend `admin/base.html` or `base_custom_admin.html` template:\n```html\n<!-- my_template.html -->\n{% extends 'base_custom_admin.html' with title=\"your page title\" %} \n{% block content %}\n<h1>Hello World</h1>\n{% endblock %}\n```\n\n### Important: Custom Views Must Be Registered Before Admin URLs are Loaded\n\nBe sure to import the files where your views are stored prior to loading your root url conf. For example:\n\n```python\n# project/urls.py\nfrom django.contrib import admin\n\n# importing view before url_patterns ensures it's registered!\nfrom some_app.views import YourCustomView \n\nurl_patterns = [\n   path(\"admin/\", admin.site.urls),\n   ...\n]\n```\n\n## Configurable Settings\n\n- `CUSTOM_ADMIN_DEFAULT_APP_LABEL`: set to override the default app_label (default: `django_custom_admin_pages`)\n\n## Contributing\n\nReach out to the author if you'd like to contribute! Also free to file bug reports or feature requests via [github issues](https://github.com/lekjos/django-custom-admin-pages/issues).\n\n### Local Development\n\nTo start the test_project:\n- `cd <repo_root>`\n- `poetry install --with dev`\n- `python test_proj/manage.py migrate`\n- `python test_proj/manage.py createsuperuser` (follow prompts)\n- `python test_proj/manage.py runserver`\n- Navigate too `localhost:8000/admin`, log in, and there should be one custom admin view.\n\nTo run the test suite:\n- `poetry run pytest`\n\nPrior to committing:\n1. Run pylint:\n   - `cd <repo_root>`\n   - `poetry run pylint django_custom_admin_pages/`\n\n2. Run black:\n   - `poetry run black .`\n\n2. Run isort:\n   - `poetry run isort django_custom_admin_pages/`\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "A django app that lets you add standard class-based views to the django admin index and navigation.",
    "version": "1.2.4",
    "project_urls": {
        "Homepage": "https://github.com/lekjos/django-custom-admin-pages",
        "Repository": "https://github.com/lekjos/django-custom-admin-pages"
    },
    "split_keywords": [
        "django",
        "admin",
        "django-admin",
        "django admin",
        "interface",
        "customize admin",
        "custom admin",
        "customize"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "70e08d05b911119bd772b86204403835f6362392dba4b8dae7e2255718e24e5e",
                "md5": "6aa8657c31dd917898a16119677cf13c",
                "sha256": "71502d955fb0df7ef2ef7efa3d2e175a229dffff412fbf35eb9ee5c82b538a01"
            },
            "downloads": -1,
            "filename": "django_custom_admin_pages-1.2.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6aa8657c31dd917898a16119677cf13c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 84166,
            "upload_time": "2023-11-12T18:09:45",
            "upload_time_iso_8601": "2023-11-12T18:09:45.719954Z",
            "url": "https://files.pythonhosted.org/packages/70/e0/8d05b911119bd772b86204403835f6362392dba4b8dae7e2255718e24e5e/django_custom_admin_pages-1.2.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "70048cb217f57218b2ae0b4ec382d174f46e2539b437686b4d21f6370dbd850c",
                "md5": "1d26cca81c70827097753ec90cebea48",
                "sha256": "850d91394ac419595883158bcb0c77ded621dded621e8ed4e647d2ad2f5f0859"
            },
            "downloads": -1,
            "filename": "django_custom_admin_pages-1.2.4.tar.gz",
            "has_sig": false,
            "md5_digest": "1d26cca81c70827097753ec90cebea48",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 63352,
            "upload_time": "2023-11-12T18:09:47",
            "upload_time_iso_8601": "2023-11-12T18:09:47.394614Z",
            "url": "https://files.pythonhosted.org/packages/70/04/8cb217f57218b2ae0b4ec382d174f46e2539b437686b4d21f6370dbd850c/django_custom_admin_pages-1.2.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-12 18:09:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lekjos",
    "github_project": "django-custom-admin-pages",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "django-custom-admin-pages"
}
        
Elapsed time: 0.24762s