Adding custom button to each field od ModelAdmib using Grappelli

54 views
Skip to first unread message

Filip Bajaník

unread,
Jul 4, 2014, 3:52:58 AM7/4/14
to django...@googlegroups.com

I use Grappelli as a custom admin sites plugin...

I use hard-coded button in list_display in the each field which looks like this

def approve_button(self):
    return u"<input type='button' class='grp-button' value='%s' onclick='if (confirm(\"%s\")){django.jQuery.get(\"/approve/%s/%s/\", function(data){alert(data);})}'>" % (_("Approve"), _("Are you sure you want to approve this request?"), self.id, self.license_ticket.id)
approve_button.allow_tags = True

The problem is, that I have list_editable ForeignKey and I want to choose an element from the list, hit the button and send self.license_ticket.id to /approve/%s/%s. Sending id is simple, but the list has to be saved after clicking on the Approve button.

One solution is to choose from the list, hit the Save button at the bottom of the page and then hit the Approve button, which is solution I don't like.

Reply all
Reply to author
Forward
0 new messages