django-etc
django-etc copied to clipboard
Submit input value not in request.POST
I added some more buttons in the submit_line.html as different guides say (https://stackoverflow.com/questions/67463654/add-custom-button-near-save-button-django-admin, you%20need%20to%20override%20%22change_form.).
I just don't get the value of the button I pressed, I noticed that it works with all django models, except with the admins created with etc.admin.CustomModelPage
.
Not even if I try to activate the save buttons, etc like this:
def view_custom(self, request):
context: dict = {
'show_save_and_continue': True,
'show_save_and_add_another': True,
'show_save_as_new': True,
'show_save': True,
.........
return self._changeform_view(request, object_id=None, form_url='', extra_context=context)
The value of the submit on click is not passed.
I just don't get the value of the button I pressed, [...]
And how and there do you try to get that value?
What's in self.bound_request.POST
in model.save()
?
in Admin response_add:
def response_add(self, request, obj):
a4 = request.POST.get('_button_name')
if '_button_name' in request.POST:
self.test(request, obj)
return super().response_add(request, obj)
But model.save()
is called before response_add
.
There is nothing here either, even if I try to use django's default buttons, _save, _saveasnew, _continue, they are not taken in this POST
There is nothing here either, [...]
Use F12 in broswer developer console to see what data is actually submitted to server. N.b.: only a value of the pressed button is submitted (not others).
Already seen, the first image refers to an admin created with your library, it does not send me information about the button, the second refers to an admin created via django and sends me information about the button.
Already seen, the first image refers to an admin created with your library, it does not send me information about the button, [...]
It's time to look at the html: 1. one that sends; 2. another that fails to send. Please save those and attach here.
I just override submit_line.html like this:
{% load i18n admin_urls %}
<div class="submit-row">
{% block submit-row %}
{% if testbla %}<input type="submit" value="{% translate 'test 2' %}" name="_test 2">{% endif %}
{% if testblabla %}<input type="submit" value="{% translate 'test' %}" name="_test">{% endif %}
{% if show_save %}<input type="submit" value="{% translate 'Save' %}" class="default" name="_save">{% endif %}
{% if show_delete_link and original %}
{% url opts|admin_urlname:'delete' original.pk|admin_urlquote as delete_url %}
<p class="deletelink-box"><a href="{% add_preserved_filters delete_url %}" class="deletelink">{% translate "Delete" %}</a></p>
{% endif %}
{% if show_save_as_new %}<input type="submit" value="{% translate 'Save as new' %}" name="_saveasnew">{% endif %}
{% if show_save_and_add_another %}<input type="submit" value="{% translate 'Save and add another' %}" name="_addanother">{% endif %}
{% if show_save_and_continue %}<input type="submit" value="{% if can_change %}{% translate 'Save and continue editing' %}{% else %}{% translate 'Save and view' %}{% endif %}" name="_continue">{% endif %}
{% if show_close %}<a href="{% url opts|admin_urlname:'changelist' %}" class="closelink">{% translate 'Close' %}</a>{% endif %}
{% endblock %}
</div>
Only these 2 lines have been added, the template is from django 3.2.20
{% if testbla %}<input type="submit" value="{% translate 'test 2' %}" name="_test 2">{% endif %}
{% if testblabla %}<input type="submit" value="{% translate 'test' %}" name="_test">{% endif %}
The rendered html I meant, not the templates.
I updated the first comment, the first image is from the admin with etc, the second is not
Were you able to replicate the problem?
I see to reason for an html not to send the data. My guess is that you're trying to compare two different cases: one from edit page, another from a popup or something (thence the Close
link). Please compare the same pages with and w/o django-etc: chances that the behaviour is not related to the app, since the app doesn't do anything with templates.