handle cached_property as well as regular properties in our camp filtering on @property in CampViewMixin

This commit is contained in:
Thomas Steen Rasmussen 2018-06-03 17:16:00 +02:00
parent bff5bb292e
commit 64f4eebac3
1 changed files with 3 additions and 2 deletions

View File

@ -1,5 +1,6 @@
from camps.models import Camp
from django.shortcuts import get_object_or_404
from django.utils.functional import cached_property
class CampViewMixin(object):
@ -20,8 +21,8 @@ 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):
# check if we have a camp property or cached_property, filter if so
if hasattr(queryset[0], 'camp') and (isinstance(getattr(type(queryset[0]), 'camp', None), property) or isinstance(getattr(type(queryset[0]), 'camp', None), cached_property)):
for item in queryset:
if item.camp != self.camp:
queryset = queryset.exclude(pk=item.pk)