0

enter image description here

As shown above, after press Export button, only "Django 1" returns through the print() command.

Wondering hwo to get all three values from this kind of interactive?

# admin.py
def export(self, request, queryset):
        if "apply" in request.POST:
            queryset.update(status="exported")
            title = request.POST['title']
            print(title, _selected_action)

            self.message_user(request,
                              "Changed status on {} orders".format(queryset.count()))
            return HttpResponseRedirect(request.get_full_path())

        context = admin.site.each_context(request)  
        context.update({
            'data': queryset
        })             
        return render(request, 'admin/export.html', context=context)
    export.short_description = "export"

<!-- export.html -->
{% extends "admin/base_site.html" %}
{% block content %}

<form action="" method="POST">
    {% csrf_token %}
    {% for d in data %}
        <p>
            {{ d.pk }}.{{ d }}
            <input type="text" name="title" value={{ d.title }} size="50" autofocus />
        </p>
    <input type="hidden" name="_selected_action" value="{{ d.pk }}" />
    {% endfor %}

    <input type="hidden" name="action" value="export" />
    <input type="submit" name="apply" value="Export" />
</form>
{% endblock %}

4
  • 3
    request.POST.getlist('title') May 9, 2019 at 13:19
  • @DanielRoseman Tried, but it returns "'QueryDict' object has no attribute 'get_list'"
    – mrhaoji
    May 9, 2019 at 13:23
  • It's not get_list, but getlist. May 9, 2019 at 13:23
  • @DanielRoseman ouch, thx!
    – mrhaoji
    May 9, 2019 at 13:31

1 Answer 1

0

As @DanielRoseman mentioned in the comment area, request.POST.getlist('title') works well here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.