Iterate over camo_filter and return the first one that returns results! (#243)

This commit is contained in:
Víðir Valberg Guðmundsson 2018-07-16 16:07:38 +02:00 committed by Thomas Steen Rasmussen
parent 7f9dfdd6e1
commit 8ac973bc61

View file

@ -17,8 +17,16 @@ class CampViewMixin(object):
def get_queryset(self):
queryset = super(CampViewMixin, self).get_queryset()
if queryset:
camp_filter = {self.model.get_camp_filter(): self.camp}
return queryset.filter(**camp_filter)
camp_filter = self.model.get_camp_filter()
# Let us deal with eveything as a list
if isinstance(camp_filter, str):
camp_filter = [camp_filter]
for _filter in camp_filter:
result = queryset.filter(**{_filter: self.camp})
if result.exists():
return result
# Camp relation not found, or queryset is empty, return it unaltered
return queryset