Custom Search

SUBSCRIBE

SUBSCRIBE : 300 + Free Video Tutorials Programming (Python, golang, Julia), DevOps

Wednesday, August 20, 2014

Django ModelAdmin add custom checkbox in the table

* Create a new method "action_checkbox2" in "ModelAdmin" class.

* Add the name of this new method in class variable "list_display" of "ModelAdmin" class.

* See django/contrib/admin/options.py and django/contrib/admin/helpers.py
class OurModelAdmin(admin.ModelAdmin):

    list_display = ('action_checkbox2', 'year', 'book', 'user')

    def action_checkbox2(self, obj):
        """
        A list_display column containing a checkbox widget.
        """
        from django.contrib.admin import helpers
        from django.utils.encoding import force_text
        return helpers.checkbox.render("_selected_action2", force_text(obj.pk))
    from django.utils.safestring import mark_safe   
    action_checkbox2.short_description = mark_safe('')
    action_checkbox2.allow_tags = True

No comments:

Post a Comment