Custom Search

Wednesday, August 20, 2014

Django ModelAdmin ActionForm action_checkbox replace id with different field

* Override the method "action_checkbox" of "ModelAdmin" class and change "obj.pk" with "obj.your_field"

* See django/contrib/admin/options.py and django/contrib/admin/helpers.py

class OurModelAdmin(admin.ModelAdmin):

    def action_checkbox(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(helpers.ACTION_CHECKBOX_NAME, force_text(obj.pk))




No comments:

Post a Comment