From b602e394feea3f9d85599b95645a4e14138e6df6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Tue, 17 Jul 2018 20:46:30 +0200 Subject: [PATCH] Fix CampViewMixin to deal properly with multiple camp_filters when dealing with SingleObjectMixin based CBVs --- src/camps/mixins.py | 6 +++++- src/program/models.py | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/camps/mixins.py b/src/camps/mixins.py index e16dd840..2a4ad5bb 100644 --- a/src/camps/mixins.py +++ b/src/camps/mixins.py @@ -24,7 +24,11 @@ class CampViewMixin(object): camp_filter = [camp_filter] for _filter in camp_filter: - result = queryset.filter(**{_filter: self.camp}) + filter_dict = {_filter: self.camp} + if hasattr(self, 'pk_url_kwarg'): + # We should also filter for the pk of the object + filter_dict['pk'] = str(self.kwargs.get(self.pk_url_kwarg)) + result = queryset.filter(**filter_dict) if result.exists(): return result diff --git a/src/program/models.py b/src/program/models.py index 22a58381..e7464b7d 100644 --- a/src/program/models.py +++ b/src/program/models.py @@ -146,7 +146,12 @@ class Url(CampRelatedModel): def camp(self): return self.owner.camp - camp_filter = 'owner__camp' + camp_filter = [ + 'speakerproposal__camp', + 'eventproposal__track__camp', + 'speaker__camp', + 'event__track__camp', + ] ###############################################################################