fix next_event and previous_event if there isn't one

This commit is contained in:
2021-12-11 10:27:50 -06:00
parent 5bd6bad1a7
commit ecb25abd71
2 changed files with 74 additions and 69 deletions

View File

@@ -2,17 +2,21 @@
{% with events_active="active" %}
{% block precontent %}
<div class="d-flex justify-content-center justify-content-md-center border-bottom bg-white">
{% if previous_event %}
<a class="btn btn-outline-secondary btn-sm d-md-flex my-auto align-items-md-center my-3 mx-3" href="{% url 'edit lineup' event_id=previous_event.id %}" role="button">
<i class="bi bi-chevron-left"></i>{{ previous_event.start|date:"D" }}&nbsp;{{ previous_event.start|date:"n/j" }}
</a>
{% endif %}
<div>
<h5 class="text-center m-1">{{ event.away_team.name }} vs. {{ event.home_team.name }}</h5>
<p class="text-center text-muted m-1">{{ event.start|date:"l, F j, Y g:i A" }}<br>{{ event.venue.name }}</p>
<h6 class="text-muted m-1"></h6>
</div>
{% if next_event %}
<a class="btn btn-outline-secondary btn-sm align-items-center my-auto my-3 mx-3" href="{% url 'edit lineup' event_id=next_event.id %}" role="button">
{{ next_event.start|date:"D" }}&nbsp;{{ next_event.start|date:"n/j" }}<i class="bi bi-chevron-right"></i>
</a>
{% endif %}
</div>
<ul class="nav nav-pills nav-fill bg-white" role="tablist">

View File

@@ -35,7 +35,7 @@ def edit(request, event_id):
else:
pass
return render(request, 'success.html', {'call_back':'edit lineup','id':event_id, 'errors':[error for error in formset.errors if error]}, status=200)
previous_event = Event.objects.get(id=event_id-1)
previous_event = Event.objects.filter(id=event_id-1).first()
event = Event.objects.get(id=event_id)
next_event = Event.objects.get(id=event_id+1)
@@ -86,7 +86,8 @@ def edit(request, event_id):
}
return render(request, 'lineups/lineup.html', {'title': 'Lineup',
'event': event, 'details':details,
'event': event,
'details':details,
'previous_event': previous_event,
'next_event': next_event,
'formset': formset,