improve editor geometry API performance using prefetch_related

This commit is contained in:
Laura Klünder 2017-05-29 16:36:17 +02:00
parent 621cb8f32e
commit c65f01d620
2 changed files with 22 additions and 10 deletions

View file

@ -112,13 +112,24 @@ class Location(LocationSlug, EditorFormMixin, models.Model):
return self._meta.verbose_name + ' ' + self.slug
return super().title
@staticmethod
def bla():
pass
def get_color(self):
if self.color:
return self.color
color_group = self.groups.filter(color__isnull=False).order_by('compiled_area', 'compiled_room').first()
if color_group:
return color_group.color
return None
# dont filter in the query here so prefetch_related works
groups = [group for group in self.groups.all() if group.color is not None]
if not groups:
return None
for group in groups:
if group.compiled_area:
return group.color
for group in groups:
if group.compiled_room:
return group.color
return groups[0].color
class SpecificLocation(Location, models.Model):