Commit 192e2859 authored by Daniel W Bond's avatar Daniel W Bond
Browse files

additional optimization with prefetch_related-- reduces queries to generate floor and room widget

parent 038b20cf
......@@ -24,12 +24,12 @@ class SelectRoomWidget(forms.widgets.Select):
print("Sorry about that, but we're currently ignoring your fancy attrs.")
# should probably type check the other fields too
if rooms is None:
self.rooms = Room.objects.all()
self.rooms = Room.objects.all().prefetch_related('floor')
else:
if not all(isinstance(thing, Room) for thing in rooms):
raise TypeError("Rooms in a SelectRoomWidget must all be Rooms!")
if floors is None:
self.floors = Floor.objects.all()
self.floors = Floor.objects.all().prefetch_related('building')
if buildings is None:
self.buildings = Building.objects.all()
if neighborhoods is None:
......
......@@ -26,7 +26,7 @@
{% load cache %}
{% cache 3600 floor_list %}
{% for floor in floors %}
<option value="{{ floor.pk }}" class="{{ floor.building.name }}">{{ floor.number|ordinal }}</option>
<option value="{{ floor.pk }}" class="{{ floor.building.name }}">{{ floor.number|ordinal }}</option>
{% endfor %}
{% endcache %}
</select>
......@@ -35,7 +35,7 @@
<option value="">---</option>
{% cache 3600 room_list %}
{% for room in rooms %}
<option value="{{ room.pk }}" class="{{ room.floor.pk }}">{{ room.number }}</option>
<option value="{{ room.pk }}" class="{{ room.floor.pk }}">{{ room.number }}</option>
{% endfor %}
{% endcache %}
</select>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment