Everytime I submit it quits back to model adminpage without executing anything.
I'm trying to let there be an interim page for approval purposes. But it either doesn't notice submit or the submit has already happened on page load in other applications.
forms.py
class ReviewRequestTemplate(forms.Form):
emailtemplate = forms.CharField(widget=forms.Textarea, required=True)
employers_email = forms.EmailField(required=True)
admin.py
class EmployerAdmin(TranslationAdmin):
list_display = ('name', 'website', 'review_request_sent',)
actions = ['request_review',]
def request_review(self, request, queryset):
context={}
RequestTemplateFormset = formset_factory(ReviewRequestTemplate, extra=0)
formset = RequestTemplateFormset(initial=[{'emailtemplate': f'Hello {employer.name} Review our service right NOW!','employers_email':employer.email} for employer in queryset])
if 'submit' in request.POST:
print('YEES')
formset = RequestTemplateFormset(request.POST)
if formset.is_valid():
print("formset is valid")
else:
print('nooo')
context['formset'] = formset
context['selected_employers'] = queryset
return render(request, 'admin/reviewrequest.html', context)
admin/reviewrequest.html
{%extends "admin/base_site.html" %}
{% block content %}
<form action="" method="post" name="requestreviewform">
{% csrf_token %}
<input type="checkbox" value="check" name="check"> do you want to send?
{%for form in formset%}
{{form.as_p}}
{%endfor%}
<input type="submit" name="request_review" value="Send request/s">
</form>
{% endblock %}
Found another post on stackoverflow, now it works. Problem using Django admin Actions with intermediate pages
def admin_action(self, request, queryset):
RequestTemplateFormset = formset_factory(ReviewRequestTemplate, extra=0)
formset = RequestTemplateFormset(initial=[{'emailtemplate': f'Hello {employer.name} Review our servie right NOW!','employers_email':employer.email} for employer in queryset])
if request.POST.get('post'):
# process the queryset here
print('yess')
formset = RequestTemplateFormset(request.POST)
all_sent = request.POST.items()
return HttpResponse(all_sent)
else:
context = {
'title': "Are you sure?",
'queryset': queryset,
'action_checkbox_name': helpers.ACTION_CHECKBOX_NAME,
'formset': formset
}
return TemplateResponse(request, 'admin/test.html',
context)