filters.py 968 B

123456789101112131415161718192021222324252627282930
  1. from django_filters import rest_framework as filters
  2. from glitchtip.filters import StartEndRelativeIsoDateTimeRangeFilter
  3. from projects.models import Project
  4. from .models import Issue
  5. class IssueFilter(filters.FilterSet):
  6. created = StartEndRelativeIsoDateTimeRangeFilter(
  7. field_name="created",
  8. label="Issue created",
  9. )
  10. project = filters.ModelMultipleChoiceFilter(
  11. queryset=Project.objects.all(), distinct=False
  12. )
  13. class Meta:
  14. model = Issue
  15. fields = ["project", "created"]
  16. def filter_queryset(self, queryset):
  17. queryset = super().filter_queryset(queryset)
  18. # This exists because OSS did it this way, the astute observer will note
  19. # it could just as well be done in query
  20. environments = self.request.query_params.getlist("environment")
  21. if environments:
  22. queryset = queryset.filter(tags__environment__has_any_keys=environments)
  23. return queryset