Search code examples
djangodjango-templatesconditional-statementspdf-generation

Django Template strange behavior of layout


I have a function which generate a pdf.file and send it by email. And it works perfect. And I have a Table on my frontend Table

like above. In my Django Model - Point 1 set by default as False, by condition if Point 1 is False - Cell 2 is empty, else - marked as Done. When I changing Table via Django form it works fine as well (frontend marked as Done). The problem is when I trying to change this via function which generate a pdf. I have added below lines of code in my pdf.generate Function:

def generatePdf(request, pk):
   point = get_object_or_404(MyObj.objects.select_related('related'), pk=pk)
   ...
   email.send(fail_silently=False)
   point.one = True
   print(point.one)
   messages.success(request, 'Success') 
   return HttpResponseRedirect....

at the terminal I got the message that value changed properly from False to True

Terminal

but for some reason Cell 2 in my Table on the frontend still is empty... Part of frontend code:

{% for item in object_list %}
...
<td>
    {% if item.one %}
     <span><i class="fa fa-solid fa-check"></i></span>
    {% else %}
     <span></span>
    {% endif %}
</td>
...
{% endfor %}

Summarizing the above said - why frontend condition working properly only if I change via Django form (function) and not if I trying to change via generatePdf function? Cell value in database changed properly in both ways!


Solution

  • I just forgot to add:

    point.save()
    

    in order to save to database changes. So simple...