I am processing a form in my Celery task and I can already render them after HttpResponseRedirect.
Here in my views.py:
from django_celery_results.models import TaskResult
from .forms import SampleForm
from .models import Sample
from analysis.tasks import process_sample_input
def sample_submit(request):
if request.method == "POST":
form = SampleForm(request.POST or None, request.FILES or None)
if form.is_valid():
#form = form.cleaned_data
instance = form.save()
task = process_sample_input.delay(instance.id)
try:
task_result = TaskResult(task_id = task.id)
task_result.save()
return HttpResponseRedirect(reverse("sample:results_detail", kwargs={"id":instance.id, "task_id":task.id}))
except Exception as e:
raise e
#return results_detail(request, instance.id, task.id) #show the results details
else:
print form.errors
return not_processed(request)
else:
form = SampleForm()
context = {
"form": form,
}
return render(request, "analysis/sample_form.html", context)
My problem is how can I access the html rendered by results_detail from a results list page. I don't know how I can access my Celery task ID elsewhere from the views' sample_submit()
In my views.py:
def results_list(request):
all_samples = Sample.objects.all()
context = {'all_samples': all_samples}
return render(request, "analysis/results_list.html", context)
In my results_list.html
{% block content %}
<table>
<thead>
<tr>
<th>Name [Local File or URL]</th>
</tr>
</thead>
{% for sample in all_samples %}
<td><a href='/sample/results/{{sample.id}}/'>{{ sample.get_sample_name }}</a></td>
{% endfor %}
</table>
{% endblock %}
in the myapp/analysis/urls.py:
url(r'^results/(?P<id>[0-9]+)/$', views.results_detail, name="results_detail"),
Here in urls.py and templates, I can pass only one parameter. How can I pass the Celery taskresult id (auto-generated) to the views if there is a way? Any help or ideas?