Answer the question
In order to leave comments, you need to log in
Why is the controller class in django inherited from ListView not updating the data after changing the database?
Here is the code for this controller in views.py
# python 3.5, django 1.9
from django.utils import timezone
from creation.models import Game
from django.views.generic.list import ListView
class GameList(ListView):
template_name = "gamelist.html"
queryset = Game.objects.order_by("-end")
paginate_by = 20
def get_context_data(self, **kwargs):
context = super(GameList, self).get_context_data(**kwargs)
context["User"] = self.request.user
context["next"] = []
context["now"] = []
context["time"] = timezone.now()
for i in self.queryset:
if i.start > timezone.now():
context["next"].append(i)
elif i.end > timezone.now():
context["now"].append(i)
else: break
context["next"].reverse()
return context
{% if next %}
<p class="next"></i> Ближайшие игры:</p>
{% for game in next %}
<a href="{% url "infogame" code=game.code %}"> {{ game.name }} (начало: {{ game.start }})</a><br />
{% endfor %}
{% endif %}
{% if now %}
<p class="now">Текущие игры:</p>
{% for game in now %}
<a href="{% url "infogame" code=game.code %}">> {{ game.name }} (до: {{ game.start }})</a><br />
{% endfor %}
{% endif %}
<p class="games">Все прошедшие игры:</p>
{% for game in object_list %}
{% if game.end < time %} <!-- игра завершена -->
<a href="{% url "infocart" code=game.code %}">> {{ game.name }} ({{ game.start }} - {{ game.end }})</a><br />
{% endif %}
{% endfor %}
Answer the question
In order to leave comments, you need to log in
The thing is that the template is generated once - during the page load. To make the content change dynamically - load data via ajax
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question