filters.py 907 B

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