views:

145

answers:

2

I'd like to write a django-admin action (for use when the user selects zero or more rows) that will allow them to edit the selected items as a group. I only need to edit one of the items in the model (the "room") at a time, but I don't want to have to go through all 480 of my objects and manually edit them one-by-one.

Is there a way to throw up an interstitial page that allows the user to edit the items as a group?

A: 

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."

John Paulett
+1  A: 

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.

jathanism