Fix CampViewMixin to deal properly with multiple camp_filters when dealing with SingleObjectMixin based CBVs

This commit is contained in:
Víðir Valberg Guðmundsson 2018-07-17 20:46:30 +02:00
parent 8ac973bc61
commit b602e394fe
2 changed files with 11 additions and 2 deletions

View file

@ -24,7 +24,11 @@ class CampViewMixin(object):
camp_filter = [camp_filter] camp_filter = [camp_filter]
for _filter in 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(): if result.exists():
return result return result

View file

@ -146,7 +146,12 @@ class Url(CampRelatedModel):
def camp(self): def camp(self):
return self.owner.camp return self.owner.camp
camp_filter = 'owner__camp' camp_filter = [
'speakerproposal__camp',
'eventproposal__track__camp',
'speaker__camp',
'event__track__camp',
]
############################################################################### ###############################################################################