diff --git a/src/camps/mixins.py b/src/camps/mixins.py index b3ec86be..ace90a55 100644 --- a/src/camps/mixins.py +++ b/src/camps/mixins.py @@ -28,16 +28,18 @@ class CampViewMixin(object): filter_dict = {_filter: self.camp} # get pk from kwargs if we have it - pk = self.kwargs.get(self.pk_url_kwarg) - if pk is not None: - # We should also filter for the pk of the object - filter_dict['pk'] = pk + if hasattr(self, 'pk_url_kwarg'): + pk = self.kwargs.get(self.pk_url_kwarg) + if pk is not None: + # We should also filter for the pk of the object + filter_dict['pk'] = pk # get slug from kwargs if we have it - slug = self.kwargs.get(self.slug_url_kwarg) - if slug is not None and (pk is None or self.query_pk_and_slug): - # we should also filter for the slug of the object - filter_dict[self.get_slug_field()] = slug + if hasattr(self, 'slug_url_kwarg'): + slug = self.kwargs.get(self.slug_url_kwarg) + if slug is not None and (pk is None or self.query_pk_and_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 result = queryset.filter(**filter_dict)