[Django]-Django Admin "Edit Selection" Action?

3👍

You are able to create custom admin actions, and using JavaScript or custom ModleForms you could easily create popup windows or alerts, or whatever you want to do. For example I have this in the admin for one of my apps:

admin.py:

def deactivate_selected(modeladmin, request, queryset):
    rows_updated = queryset.update(active=0)
    for obj in queryset: obj.save()
    if rows_updated == 1:
        message_bit = '1 item was'
    else:
        message_bit = '%s items were' % rows_updated
    modeladmin.message_user(request, '%s successfully deactivated.' % message_bit)
deactivate_selected.short_description = "Deactivate selected items"

## add deactivates 
admin.site.add_action(deactivate_selected)

This adds the option to “Deactive selected items” in the admin page.

It seems to me that it would be easy to make a custom action to “Update room for selected items” that would present a JavaScript prompt, take that input, and provide it to the custom action function to perform what you need to do.

More reading can be found on this here: Writing Django Admin Actions.

1👍

This code adds a django-admin action to do what you want http://code.google.com/p/django-mass-edit/

0👍

There may be ways of doing it in the admin, but why not just create a custom view to do this?

When you start getting into heavy customizations of the admin, it indicates that you should start writing a custom app that you can easily modify. It is actually very easy to get most of the functionality of the admin using the generic views.

Remember, “The Admin is not your app.

0👍

You can download django-admin actions with pip

pip install django-adminactions

It is an app that gives you many django-admin actions, like mass edit.

See installation here: http://django-adminactions.readthedocs.io/en/latest/install.html

Leave a comment