I need to filter against a UUID field using the following query:
?groupId=<UUID>&groupId=<UUID>
This is the code I have:
2 from django_filters import rest_framework as filters
32 class CustomFilter(filters.UUIDFilter):
33 def filter(self, qs, value):
33 attr_name = next(k for k, v in self.parent.get_filters().items() if v.field_name == self.field_name)
34 if attr_name not in self.parent.data:
35 return super().filter(qs, value)
36
37 q = Q()
38 for val in self.parent.data.getlist(attr_name ):
39 q |= Q(**{f"{self.field_name}__{self.lookup_expr}": val})
40 return self.get_method(qs)(q)
MultipleChoiceField seemed like a possible approach, but I'd have to build a choice list using a DB query, which doesn't sound like a good idea (caching wouldn't work as new IDs may be created at any time)
Am I missing some built in way of doing this filtering? If not is the above something that might be beneficial to add to the library ?