Socket
Socket
Sign inDemoInstall

django-admin-wizard

Package Overview
Dependencies
0
Maintainers
1
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    django-admin-wizard

Django Admin dialogs and actions with intermediate forms


Maintainers
1

Readme

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 :)

Keywords

FAQs


Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc