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

Uploaded Source

Built Distribution

django_admin-1.3.2-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.2.tar.gz.

File metadata

  • Download URL: django-admin-1.3.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.8 CPython/2.7.12+

File hashes

Hashes for django-admin-1.3.2.tar.gz
Algorithm Hash digest
SHA256 2f507fc822b7af4191bf866b620c8a2d0e6e8641ee66ee32a73233b5eca4d04d
MD5 4323d1261803d2a7ec748aaf21694103
BLAKE2b-256 15b3f394e758942d48e4a5e2dca3f221c1e7cc0fa729017d0bc89ba882869155

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_admin-1.3.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.8 CPython/2.7.12+

File hashes

Hashes for django_admin-1.3.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 78182b41416b9d6ff469015d438911c64ce4ba210a2242da3c77e6de85c2d86b
MD5 26f22414e5c41155c1e108bbaba7171a
BLAKE2b-256 b769c3fea1bb60e45f52bcc658cae6f04a25cbf8c7e8b3257f90dfd77575214b

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