Answers for "django admin action"

1

django admin action

from django.contrib import admin
from myapp.models import Article

def make_published(modeladmin, request, queryset):
    queryset.update(status='p')
make_published.short_description = "Mark selected stories as published"

class ArticleAdmin(admin.ModelAdmin):
    list_display = ['title', 'status']
    ordering = ['title']
    actions = [make_published]

admin.site.register(Article, ArticleAdmin)
Posted by: Guest on March-24-2021
1

django admin action

# Add this code to admin.py
#example : Published Article
def make_published(modeladmin, request, queryset):
    queryset.update(status='p')
make_published.short_description = "Mark selected stories as published"
Posted by: Guest on March-24-2021

Python Answers by Framework

Browse Popular Code Answers by Language