Table Buttons to Submit Changelist Form in Django
I currently have the following admin page with a set list_editable
fields in my ActivityLogAdmin
model.
When I click "Save" on the bottom of the admin page, the request.POST data gets submitted to my form. I have the following method under my ActivityLogAdmin class:
def get_changelist_form(self, request, **kwargs):
return ActivityLogChangeListForm
However, I'm trying to add one custom button for each entry in my change list, so when I click it, the POST data should also be passed to a view so I can handle that data. However, I can't seem to pass this request.POST data of when I click the button to the view. Here's my attempt:
def approve(self, obj):
url = reverse('admin:activity_log_approve', args=[str(obj.id)])
return mark_safe(f'<button name="approve_button" type="submit"><a href="{url}">Approve</a></button>')
approve.short_description = 'Edit status'
urlpatterns = [
url(r'^(.+)/approve/$', wrap(self.approve_view),
name='events_activity_log_approve'),
def approve_view(self, request, object_id, extra_context=None):
print(request.POST['approve_button']) #Is None :( Tried with request.POST only as well
form = ActivityLogChangeListForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/panel/events/activitylog')
Do you guys know what I'm doing wrong? It's been a loong time since I worked with Django and I've wasted 2 days already on that :(
Thanks a lot in advance!