render colors in right order

This commit is contained in:
Laura Klünder 2018-12-21 19:06:29 +01:00
parent 0afdc0793d
commit 27287b8a00
3 changed files with 11 additions and 4 deletions

View file

@ -125,12 +125,17 @@ class Location(LocationSlug, AccessRestrictionMixin, TitledMixin, models.Model):
return None
def get_color(self, instance=None):
# dont filter in the query here so prefetch_related works
result = self.get_color_sorted(instance)
return None if result is None else result[1]
def get_color_sorted(self, instance=None):
# dont filter in the query here so prefetch_related works
if instance is None:
instance = self
for group in instance.groups.all():
if group.color and getattr(group.category, 'allow_'+self.__class__._meta.default_related_name):
return group.color
return (0, group.category.priority, group.priority), group.color
return None
def get_icon(self):