[Fixed]-Django: Run scripts from admin by selecting object's name

1👍

What you are after is admin actions. You write a custom function in the admin, and assign the function name to the admin_actions property.

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

class TaskAdmin(admin.ModelAdmin):
    list_display = ['title', 'completed']
    ordering = ['created']
    actions = [incomplete_tasks,]

admin.site.register(Task, TaskAdmin)

https://docs.djangoproject.com/en/1.8/ref/contrib/admin/actions/

https://godjango.com/78-custom-django-admin-actions/

Leave a comment