Custom Django Admin Actions

Doing bulk data actions in the admin is easy, if you know how to do it. In this video you will learn how to create your own custom admin actions so you can update a lot of data objects all at the same time.
Download HD Version next video: Namespaced Urls


Admin actions


from django.contrib import admin

from .models import Task

def all_tasks(modeladmin, request, queryset):
    for qs in queryset:
        print qs.title

def complete_tasks(modeladmin, request, queryset):
complete_tasks.short_description = 'Mark as Complete'

def incomplete_tasks(modeladmin, request, queryset):
incomplete_tasks.short_description = 'Mark as Not Complete'

class TaskAdmin(admin.ModelAdmin):
    list_display = ['title', 'completed']
    ordering = ['created']
    actions = [complete_tasks, incomplete_tasks, all_tasks], TaskAdmin)
comments powered by Disqus