darklow / django-suit

Modern theme for Django admin interface
http://djangosuit.com/
Other
2.32k stars 704 forks source link

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

Open jayWarr opened 6 years ago

jayWarr commented 6 years ago

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.

gamesbook commented 6 years ago

See #672

gamesbook commented 6 years ago

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"....