only check for pk and slug when relevant

This commit is contained in:
Thomas Steen Rasmussen 2018-07-17 22:47:14 +02:00
parent 32e9b7c40b
commit 340a3eb58c

View file

@ -28,16 +28,18 @@ class CampViewMixin(object):
filter_dict = {_filter: self.camp} filter_dict = {_filter: self.camp}
# get pk from kwargs if we have it # get pk from kwargs if we have it
pk = self.kwargs.get(self.pk_url_kwarg) if hasattr(self, 'pk_url_kwarg'):
if pk is not None: pk = self.kwargs.get(self.pk_url_kwarg)
# We should also filter for the pk of the object if pk is not None:
filter_dict['pk'] = pk # We should also filter for the pk of the object
filter_dict['pk'] = pk
# get slug from kwargs if we have it # get slug from kwargs if we have it
slug = self.kwargs.get(self.slug_url_kwarg) if hasattr(self, 'slug_url_kwarg'):
if slug is not None and (pk is None or self.query_pk_and_slug): slug = self.kwargs.get(self.slug_url_kwarg)
# we should also filter for the slug of the object if slug is not None and (pk is None or self.query_pk_and_slug):
filter_dict[self.get_slug_field()] = slug # we should also filter for the slug of the object
filter_dict[self.get_slug_field()] = slug
# do the filtering and return the result # do the filtering and return the result
result = queryset.filter(**filter_dict) result = queryset.filter(**filter_dict)