Skip to main content

Django Admin Extensions

Project description

Django Admin Extensions

Installation

pip install django-admin

Usage

Disable Action:

from django.contrib import admin
from django_admin import DeleteModelAdmin

# Override action ``delete_selected``, call ``delete_model`` for each when ``delete_selected``
class XXXAdmin(admin.ModelAdmin, DeleteModelAdmin):
    def delete_model(self, request, obj):
        obj.delete()
        # Other Codes

# Reopen action ``delete_selected`` after ``admin.site.disable_action('delete_selected')``
class YYYAdmin(admin.ModelAdmin):
    actions = ['delete_selected']

# Disable ``actions``
class ZZZAdmin(admin.ModelAdmin):
    actions = None

Export Excel:

from django.contrib import admin
from django_admin import ExportExcelModelAdmin, AdvancedExportExcelModelAdmin

class XXXAdmin(ExportExcelModelAdmin, admin.ModelAdmin):
    pass

class YYYAdmin(AdvancedExportExcelModelAdmin, admin.ModelAdmin):
    excel_headers = ()
    excel_fields = ()
    excel_fields_exclude = ()
    extra_excel_fields = ()

    def add_extra_excel_fields(self, request, query):
        return []

All Fields Readonly:

from django.contrib import admin
from django_admin import ReadonlyModelAdmin, Readonly2ModelAdmin

class XXXAdmin(ReadonlyModelAdmin, admin.ModelAdmin):
    """ Readonly for Update. """
    pass

class XXXAdmin(Readonly2ModelAdmin, admin.ModelAdmin):
    """ Readonly for Add/Update. """
    pass

Disable Editing:

from django.contrib import admin
from django_admin import ReadOnlyModelAdmin

class XXXAdmin(ReadOnlyModelAdmin, admin.ModelAdmin):
    pass

* Should add ``django_admin`` in ``INSTALLED_APPS``
```python
INSTALLED_APPS = [
    ...
    'django_admin',
    ...
]
```

Disable Add/Delete:

from django.contrib import admin
from django_admin import ChangeOnlyModelAdmin

class XXXAdmin(ChangeOnlyModelAdmin, admin.ModelAdmin):
    pass

Disable Add/Change:

from django.contrib import admin
from django_admin import DeleteOnlyModelAdmin, DeleteonlyModelAdmin

class XXXAdmin(DeleteOnlyModelAdmin, admin.ModelAdmin):
    # DeleteOnlyModelAdmin - All Fields Default Readonly
    # DeleteonlyModelAdmin - All Fields Not Default Readonly
    pass

* Should add ``django_admin`` in ``INSTALLED_APPS``
```python
INSTALLED_APPS = [
    ...
    'django_admin',
    ...
]
```

Disable Delete/Change:

from django.contrib import admin
from django_admin import AddOnlyModelAdmin

class XXXAdmin(AddOnlyModelAdmin, admin.ModelAdmin):
    pass

* Should add ``django_admin`` in ``INSTALLED_APPS``
```python
INSTALLED_APPS = [
    ...
    'django_admin',
    ...
]
```

Disadvantage

Will disable ``delete_selected`` for all ``ModelAdmin``
Will lost delete confirm

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-1.3.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

django_admin-1.3.0-py2.py3-none-any.whl (7.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-admin-1.3.0.tar.gz.

File metadata

File hashes

Hashes for django-admin-1.3.0.tar.gz
Algorithm Hash digest
SHA256 a5e1554b0ae7ca1764fcc7c3da8070f3c736b001f3cad1c93d179732959150c5
MD5 8da29f19ba7950d5eccc730ff4f581cd
BLAKE2b-256 7841e48b29f7110e5fbde0a9574dccd5bf06cfaf41a33a0418c8beeed5573916

See more details on using hashes here.

File details

Details for the file django_admin-1.3.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_admin-1.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 df4326135d62352d97c9957464f559b22b9dfd4ca6faed77ade1173912bbfb1c
MD5 5f889f258652ed75b7716a10aef4420f
BLAKE2b-256 87b7c6c9727dc635232972b36e80864fc0de767ab5515422ae542c072319499f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page