Created
June 4, 2013 07:03
-
-
Save gladson/5704110 to your computer and use it in GitHub Desktop.
Admin actions: Activated and Deactivated => https://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NameAnyModelAdmin(admin.ModelAdmin): | |
fields = ('field1', ('field2', 'field_checkbox'),) | |
list_display = ('field1', 'field2', 'field_checkbox',) | |
search_fields = ('field1',) | |
actions = ['field_checkbox_action'] | |
def field_checkbox_action(self, request, queryset): | |
for obj in queryset: | |
if obj.field_checkbox == False: | |
obj.field_checkbox = True | |
menssagem = "{0} Habilitado com sucesso!".format(queryset.count()) | |
else: | |
obj.field_checkbox = False | |
menssagem = "{0} Desabilitado com sucesso!".format(queryset.count()) | |
obj.save() | |
self.message_user(request,"{0}".format(menssagem)) | |
field_checkbox_action.short_description = "Habilitado ou Desabilitado" | |
admin.site.register(NameAnyModel, NameAnyModelAdmin) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment