I have a long process wherein my application communicates with a server, saves a model based on the server's response, and restarts its communication. I'd like to present the user with a loading page which updates whenever a model is saved. For example:
Working on request 1...
Saving model 1...
Working on request 2...
Saving model 2...
Finished task.
[Back to Homepage]
I've read through this(jango - show loading message during long processing) and its links; the first suggestion would not work, and the second requires threading, caching, etc. I've also read through the documentation for Signals
.
Let's say the model which is saved is ModelAfterResponse
. My view might look like this:
@receiver(post_save, sender=ModelAfterResponse)
def loading_page(sender, instance, created, **kwargs):
model_name = kwargs['instance'].name
return render(request, 'name/javascript_template.html', {"name": name}, content_type="application/x-javascript")
And the javascript_template.html
might look like this:
<script>
$('#some_loading_page_specific_div').innerHTML = "Working on " + {{ name }}
</script>
This is just quick mock-code—but do I have the gist of it? When I decorate a function as above, and do something simple like return HttpResponse(":D")
, nothing happens—everything continues running and :D
is nowhere to be found.
I believe I'm on the right track. Is there a simple way to accomplish what I'm looking for?