Correction bug édit lieux

Fix #133
This commit is contained in:
Jean-Marie Favreau 2024-09-09 22:19:51 +02:00
parent c0b1369f56
commit a180534be2
3 changed files with 15 additions and 8 deletions

View File

@ -70,7 +70,7 @@
{% if past %}
<a href="{% url 'view_place' object.pk %}" role="button">Voir les événements à venir</a>
{% else %}
<a href="{% url 'view_place_past' object.pk 'past' %}" role="button">Voir les événements passés</a>
<a href="{% url 'view_place_past' object.pk %}" role="button">Voir les événements passés</a>
{% endif %}
</div>
{% if object_list %}

View File

@ -142,7 +142,7 @@ urlpatterns = [
),
path("404/", page_not_found, name="page_not_found"),
path("500/", internal_server_error, name="internal_server_error"),
path("place/<int:pk>/<past>", PlaceDetailView.as_view(), name="view_place_past"),
path("place/<int:pk>/past", PlaceDetailViewPast.as_view(), name="view_place_past"),
path("place/<int:pk>", PlaceDetailView.as_view(), name="view_place"),
path("place/<int:pk>/edit", PlaceUpdateView.as_view(), name="edit_place"),
path("place/<int:pk>/delete", PlaceDeleteView.as_view(), name="delete_place"),

View File

@ -1750,17 +1750,24 @@ class PlaceDetailView(ListView):
def get_queryset(self):
self.place = get_object_or_404(Place, pk=self.kwargs["pk"])
logger.warning(self.kwargs)
self.past = "past" in self.kwargs
if self.past:
return Event.objects.filter(exact_location=self.place).filter(start_day__lte=datetime.now()).order_by("-start_day")
else:
return Event.objects.filter(exact_location=self.place).filter(start_day__gte=datetime.now()).order_by("start_day")
return Event.objects.filter(exact_location=self.place).filter(start_day__gte=datetime.now()).order_by("start_day")
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["object"] = self.place
return context
class PlaceDetailViewPast(PlaceDetailView):
def get_queryset(self):
self.place = get_object_or_404(Place, pk=self.kwargs["pk"])
self.past = True
return Event.objects.filter(exact_location=self.place).filter(start_day__lte=datetime.now()).order_by("-start_day")
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["past"] = self.past
return context