Don't duplicate existing rooms when importing schedule CSV

* Old implementation needs to see exactly the same rooms in exactly
  the same order every time it loads new data, otherwise it will
  create a duplicate entry for the room that differs only in display
  order.
* New implementation ignores the display order when checking to see
  if the room already exists.
This commit is contained in:
James Polley 2017-12-03 16:15:19 +11:00
parent cfc19f309f
commit 3239bbe29a

View file

@ -96,7 +96,11 @@ class ScheduleSectionForm(forms.Form):
created_rooms = []
rooms = sorted(set([x[self.ROOM_KEY] for x in data]))
for i, room in enumerate(rooms):
room, created = Room.objects.get_or_create(
try:
room = Room.objects.get(schedule=self.schedule, name=room)
created = False
except Room.DoesNotExist:
room = Room.objects.create(
schedule=self.schedule, name=room, order=i
)
if created: