1. pombredanne
  2. cciw-website2

Commits

Luke Plant  committed 3e9215f

Fixed/added use of prefetch_related

  • Participants
  • Parent commits e1bef33
  • Branches bookings

Comments (0)

Files changed (3)

File cciw/cciwmain/common.py

View file
     if _thisyear is None or _thisyear_timestamp is None \
         or (datetime.datetime.now() - _thisyear_timestamp).seconds > 3600:
         from cciw.cciwmain.models import Camp
-        lastcamp = Camp.objects.prefetch_related().order_by('-end_date')[0]
+        lastcamp = Camp.objects.prefetch_related(None).order_by('-end_date')[0]
         if lastcamp.is_past():
             _thisyear = lastcamp.year + 1
         else:

File cciw/officers/admin.py

View file
     list_filter = ['camp']
     search_fields = ['officer__first_name', 'officer__last_name', 'officer__username']
 
+    def queryset(self, *args, **kwargs):
+        return super(InvitationAdmin, self).queryset(*args, **kwargs).prefetch_related('camp__leaders')
+
 
 class ReferenceFormAdmin(admin.ModelAdmin):
     save_as = False

File cciw/officers/models.py

View file
 class InvitationManager(models.Manager):
     use_for_related_fields = True
     def get_query_set(self):
-        return super(InvitationManager, self).get_query_set().select_related('officer', 'camp__chaplain', 'camp__leaders')
+        return super(InvitationManager, self).get_query_set().select_related('officer', 'camp', 'camp__chaplain')
 
 
 class Invitation(models.Model):