Skip to content

Commit

Permalink
Merge pull request #330 from ochan1/tutoring-multiple-rooms
Browse files Browse the repository at this point in the history
Fix slot_id syncing to be in order correctly
  • Loading branch information
ochan1 authored Sep 13, 2021
2 parents 43cf11b + a4b21ab commit 2155095
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions hknweb/tutoring/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,13 @@ class SlotAdmin(admin.ModelAdmin):

def resync_slot_id(self, request, queryset):
queryset_ordered = queryset.order_by(
"room__id", "timeslot__hour", "timeslot__day"
"timeslot__hour", "timeslot__day", "room__id"
)
id_num = -1
last_room_id = float("inf")
slot_id = 0
for slot_query in queryset_ordered:
if slot_query.room.id <= last_room_id:
id_num += 1
slot_query.slot_id = id_num
slot_query.slot_id = slot_id
slot_id += 1
slot_query.save()
last_room_id = slot_query.room.id

resync_slot_id.short_description = "Resync Slot ID in order of time (hour then day)"

Expand Down

0 comments on commit 2155095

Please sign in to comment.