Skip to main content

Django Admin dialogs and actions with intermediate forms

Project description

django-admin-wizard

django-admin-wizard is a Django app providing helpers for django admin actions with intermediate forms.

Build Status codecov PyPI version

Description

Do you know "delete selected" action in Django-admin? This package provides helpers for creating such actions with intermediate forms in two lines of code. Also, you may add a link from django admin change page to a custom form view to perform some form-supplied action on single object.

Installation

pip install django-admin-wizard

Working example is in testproject.testapp.

  1. Add application to installed apps in django settings:
    INSTALLED_APPS.append('admin_wizard')
    
  2. And an action to your admin:
    from django.contrib import admin
    from admin_wizard.admin import UpdateAction
    
    from testproject.testapp import forms, models
    
    
    @admin.register(models.MyModel)
    class MyModelAdmin(admin.ModelAdmin):
        actions = [UpdateAction(form_class=forms.RenameForm)]
    
  3. Add custom view to your admin:
    from django.contrib import admin
    from django.urls import path
    from admin_wizard.admin import UpdateDialog
    
    from testproject.testapp import forms, models
    
    
    @admin.register(models.MyModel)
    class MyModelAdmin(admin.ModelAdmin):
    
        def get_urls(self):
            urls = [
                path('<int:pk>/rename/',
                     UpdateDialog.as_view(model_admin=self,
                                          model=models.MyModel,
                                          form_class=forms.RenameForm),
                     name='rename')
            ]
            return urls + super().get_urls()
    
  4. Add a link to custom dialog in admin change page:
    from django.contrib import admin
    from django.urls import reverse
    
    from testproject.testapp import models
    
    
    @admin.register(models.MyModel)
    class MyModelAdmin(admin.ModelAdmin):
       readonly_fields = ('update_obj_url',)
    
       def update_obj_url(self, obj):
           # FIXME: it's XSS, don't copy-paste
           url = reverse('admin:rename', kwargs=dict(pk=obj.pk))
           return f'<a href="{url}">Rename...</a>'
       update_obj_url.short_description = 'rename'
    

Now you have "rename" action in changelist and "rename" link in change view. Enjoy :)

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-wizard-0.5.1.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

django_admin_wizard-0.5.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file django-admin-wizard-0.5.1.tar.gz.

File metadata

  • Download URL: django-admin-wizard-0.5.1.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for django-admin-wizard-0.5.1.tar.gz
Algorithm Hash digest
SHA256 7ba24c129268b531e4818890542154d380b3ced2cead8419aa3c908df7cf632a
MD5 5b382da80eeef4285abb61f8593285d4
BLAKE2b-256 6a79fe31432db2125ba7fdb980c466f87e7ca71b45a4cf5274928cacd5194456

See more details on using hashes here.

File details

Details for the file django_admin_wizard-0.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_admin_wizard-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 588917e14bebf8d4ae596fc28720924f714418d8342cdb530f98135a6a760b15
MD5 73a343d84a4a5bf505df8f671bb2473c
BLAKE2b-256 0e84f0bbdc6db861ee399269312cc285df86a4da9d53f2e0018f6d637193387d

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