I have a list of objects that have a country code associated with them, I would like to write a FilterSet class that can receive a list of codes ie. ['US', 'CA'] and will return a list of the objects that have the country code column set to either of those values.
It doesn't seem like filtersets may be able to do this for me, but its seems like a relatively common requirement? I was thinking maybe it's something like __in for the filterset field.
Any help is much appreciated
Filterset can do this using BaseInFilter. Example:
class CharInFilter(BaseInFilter, CharFilter):
pass
class YourFilterSet(FilterSet):
code = CharInFilter(field_name='code', lookup_expr='in')
class Meta:
model = ModelClass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With