replace fix/iter with next on queries

pull/1/head
parent 6209a2671e
commit f4a0ee55d4

@ -20,20 +20,16 @@ def index(request):
context["my_shifts"] = helper.shiftregistration_set.filter(
shift__start_at__gt=timezone.now()
).order_by("shift__start_at")
context["current_shift"] = next(
iter(
context["current_shift"] = (
helper.shiftregistration_set.annotate(
shift_end=ExpressionWrapper(
F("shift__start_at") + F("shift__duration"),
output_field=DateTimeField(),
)
)
.filter(
shift__start_at__lte=timezone.now(), shift_end__gte=timezone.now()
)
.order_by("shift__start_at")[:1]
),
None,
.filter(shift__start_at__lte=timezone.now(), shift_end__gte=timezone.now())
.order_by("shift__start_at")
.first()
)
free_shifts = (
Shift.objects.annotate(reg_count=Count("shiftregistration"))

@ -16,26 +16,22 @@ def index(request):
def shift_overview(request):
context = {}
context["running_shifts"] = (
reg.shift
for reg in ShiftRegistration.objects.annotate(
shift_end=ExpressionWrapper(
F("shift__start_at") + F("shift__duration"),
shift
for shift in Shift.objects.annotate(
end_at=ExpressionWrapper(
F("start_at") + F("duration"),
output_field=DateTimeField(),
)
)
.filter(shift__start_at__lte=timezone.now(), shift_end__gte=timezone.now())
.order_by("shift__start_at")
.filter(start_at__lte=timezone.now(), end_at__gte=timezone.now())
.order_by("start_at")
)
# probably can do some distinct/group by stuff but not sure how tih django queries
context["next_shifts"] = (
next(
iter(
Shift.objects.filter(room=room, start_at__gt=timezone.now()).order_by(
"start_at"
)
)
)
Shift.objects.filter(room=room, start_at__gt=timezone.now())
.order_by("start_at")
.first()
for room in Room.objects.all()
)

Loading…
Cancel
Save