0

I have an all_positions datapoint that uses an arrayField. So some example data looks like:

all_positions: ["C", "1B"],
all_positions: ["RP", "CP"],
all_positions: ["CP"],

I'd like to be able to make a request similar to /api/player-profiles/?all_positions=RP,CP and return the second and third examples. Essentially, I want to return all players that have ANY of the positions passed into the URL in their all_positions data.

I've read about overlap, but not sure how I would integrate that into my django-rest filters. Here is what the filter currently looks like:

class PlayerProfileFilter(django_filters.FilterSet):
    all_positions = CharInFilter(field_name='all_positions', lookup_expr='contains')
2
  • 2
    Have you changed lookup_expr='contains' to lookup_expr='overlap' Commented Jan 28, 2022 at 2:11
  • @Ahtisham that was it. Thank you! Commented Jan 29, 2022 at 2:50

1 Answer 1

2

Just change the lookup filter in lookup_expr from contains to overlap:

class PlayerProfileFilter(django_filters.FilterSet):
       all_positions = CharInFilter(field_name='all_positions', lookup_expr='overlap')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.