diff --git a/sde_collections/models/candidate_url.py b/sde_collections/models/candidate_url.py index 51c3a28b..f96e4f48 100644 --- a/sde_collections/models/candidate_url.py +++ b/sde_collections/models/candidate_url.py @@ -6,21 +6,24 @@ from .collection import Collection from .collection_choice_fields import Divisions, DocumentTypes -from .pattern import ExcludePattern, TitlePattern +from .pattern import ExcludePattern, IncludePattern, TitlePattern class CandidateURLQuerySet(models.QuerySet): - def with_exclusion_status(self): + def with_exclusion_and_inclusion_status(self): return self.annotate( excluded=models.Exists( ExcludePattern.candidate_urls.through.objects.filter(candidateurl=models.OuterRef("pk")) - ) + ), + included=models.Exists( + IncludePattern.candidate_urls.through.objects.filter(candidateurl=models.OuterRef("pk")) + ), ) class CandidateURLManager(models.Manager): def get_queryset(self): - return CandidateURLQuerySet(self.model, using=self._db).with_exclusion_status() + return CandidateURLQuerySet(self.model, using=self._db).with_exclusion_and_inclusion_status() class CandidateURL(models.Model): diff --git a/sde_collections/views.py b/sde_collections/views.py index 241979ba..b88cc92c 100644 --- a/sde_collections/views.py +++ b/sde_collections/views.py @@ -315,11 +315,12 @@ def get(self, request, *args, **kwargs): self.config_folder = config_folder return super().get(request, *args, **kwargs) + # return the urls that are either not excluded or specifically included def get_queryset(self): queryset = ( CandidateURL.objects.filter(collection__config_folder=self.config_folder) - .with_exclusion_status() - .filter(excluded=False) + .with_exclusion_and_inclusion_status() + .filter(models.Q(excluded=False) | models.Q(included=True)) ) return queryset