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

class XXXAdmin(ReadonlyModelAdmin, admin.ModelAdmin):
    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

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

Uploaded Source

Built Distribution

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

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for django-admin-1.2.3.tar.gz
Algorithm Hash digest
SHA256 4bf67f277e4fbb9211b1fb02121819c3f3b1edd1449f4ad0f73fad8a48a4051c
MD5 a1b877bfa303019b5bdbeb65df85664a
BLAKE2b-256 dfee141baf68c26e2ad6c7a7b612ba1ad646c072b9bb3f969acf81690dcc3782

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_admin-1.2.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 039769680383f7389bc396e193a23c6e75b720eadfc560109c02a19776525574
MD5 be428f4139f7e6b3af8677868e2b7f79
BLAKE2b-256 481bac5c58b88cef873041e8f2a9a285d21e66becbd38ad9498180607f79b69a

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