From aef51f0ff818ff8211e7fd1afdfcb854f1010e4f Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Wed, 10 Apr 2013 22:34:53 +0100 Subject: [PATCH] Add a set active function for Stores. --- app/stores/admin.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/stores/admin.py b/app/stores/admin.py index 0a5c512..ba87cd8 100644 --- a/app/stores/admin.py +++ b/app/stores/admin.py @@ -31,12 +31,18 @@ class StoreAdmin(admin.ModelAdmin): inlines = [ LinkInlineAdmin, ] - actions = ['add_brand', 'set_chain'] + actions = ['set_active', 'add_brand', 'set_chain'] class AddBrandForm(forms.Form): _selected_action = forms.CharField(widget=forms.MultipleHiddenInput) brand = forms.ModelChoiceField(Brand.objects) + def set_active(self, request, queryset): + with transaction.commit_on_success(): + queryset.update(active=True) + self.message_user(request, "Successfully set %d stores to active." % queryset.count()) + set_active.short_description = 'Set selected stores active.' + def add_brand(self, request, queryset): form = None if 'apply' in request.POST: