django-suit icon indicating copy to clipboard operation
django-suit copied to clipboard

Help required with model's override Add to implement batch load return

Open jayWarr opened this issue 7 years ago • 2 comments

I'm using Python 3.6, Django 2.0.4 and Suit 2.0a1

I need some help redirecting a view back to the form where it was initiated.

To explain: because of the complexities of validation I've written an independent python batch loader for my Document data model which is a member of my Poetry app.

I've overridden the ADD (record) button for the model with a template file & named it change_list.html so that the contents look like this:

{% extends "admin/change_list.html" %}
{% load i18n admin_static admin_list %}

{% block object-tools-items %}
        {% if has_add_permission %}
        <li>
            <!-- <a href="/batchload" class="addlink"> -->
            {% blocktrans with cl.opts.verbose_name as name %}Select & batch load {{ name }}s{% endblocktrans %}
          </a>
        </li>
        {% endif %}
{% endblock %}

To get the batch load to work I've put this change_list.html file in the sub-dir

templates/admin/poetry/document/

I've added the line:

`change_list_template = ('admin/poetry/document/change_list.html')`

to the: class DocumentAdmin(admin.ModelAdmin):

I've added to my urls the line:

`url(r'^batchload/$',batchLoad),`

In my poety/views.py file I have added:

from django.shortcuts import render
import subprocess


def batchLoad(request):
	cl='python3 utilities/getPoemDocuments.py'
        subprocess.run(cl, shell=True, check=True)
	return render(request,'admin/poetry/document/change_list.html')

Everything works OK ... EXCEPT When clicking on the Select & batch load documents the batch load runs fine except when it finishes and returns to execute the render statement I get this error:

error

I have two questions:

What am I doing wrong? And is there a better way to do this?

In anticipation thanks for any help.

jayWarr avatar Apr 18 '18 11:04 jayWarr

See #672

gamesbook avatar Apr 18 '18 11:04 gamesbook

PS In future it would be better to copy & paste the actual text of the error trace, rather than screenshot. This makes it searchable by "the next guy"....

gamesbook avatar Apr 18 '18 11:04 gamesbook