Luke Plant avatar Luke Plant committed e8506b8

Improved efficiency of Booking YearFilter in admin

Comments (0)

Files changed (1)

cciw/bookings/admin.py

 from django.contrib import admin
 
 from cciw.bookings.models import Price, BookingAccount, Booking
-
+from cciw.cciwmain.common import get_thisyear
 
 class PriceAdmin(admin.ModelAdmin):
     list_display = ['price_type', 'year', 'price']
     parameter_name = "year"
 
     def lookups(self, request, model_admin):
-        vals = set(Booking.objects.values_list('camp__year', flat=True))
+        # No easy way to create efficient query with Django's ORM,
+        # so hard code first year we did bookings online:
+        vals = range(2012, get_thisyear() + 1)
         return [(str(v),str(v)) for v in vals]
 
     def queryset(self, request, queryset):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.