make our CampViewMixin also filter if camp happens to be a property and not a real model field

This commit is contained in:
Thomas Steen Rasmussen 2018-03-04 17:17:57 +01:00
parent 3acab3f08c
commit 01a55ae149

View file

@ -20,5 +20,13 @@ class CampViewMixin(object):
if field.name == "camp" and field.related_model._meta.label == "camps.Camp":
return queryset.filter(camp=self.camp)
# check if we have a camp property, filter if so
if hasattr(queryset[0], 'camp') and isinstance(getattr(type(queryset[0]), 'camp', None), property):
for item in queryset:
if item.camp != self.camp:
queryset = queryset.exclude(pk=item.pk)
return queryset
# Camp relation not found, or queryset is empty, return it unaltered
return queryset