Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2026 Crash Course
NEET 2026 Crash Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
96 views
in Python by (178k points)
How can I add custom actions to Django Admin?

Please log in or register to answer this question.

1 Answer

0 votes
by (178k points)

You can add custom actions to perform batch operations on selected objects in Django Admin. Define a method in your admin class and decorate it with @admin.action to register it as an action.

Example code:

# admin.py
from django.contrib import admin
from .models import MyModel

class MyModelAdmin(admin.ModelAdmin):
    actions = ['custom_action']

    def custom_action(self, request, queryset):
        # Perform your custom action here
        for obj in queryset:
            # Do something with each selected object
            obj.some_field = True
            obj.save()

    custom_action.short_description = 'Activate selected objects'

admin.site.register(MyModel, MyModelAdmin)

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...