New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allows searching with SearchFilter in annotated fields #6240
Allows searching with SearchFilter in annotated fields #6240
Conversation
4e2aa13
to
34ee962
Compare
Argl, why won't somebody review and pull this? |
@oliwarner because it requires time and energy. |
@xordoquy sure, I can reuse it, |
34ee962
to
eadeed2
Compare
Thanks for the PR @andrzej3393. Added to the milestone to ensure it's reviewed. |
Wouldn't it be simpler to just |
eadeed2
to
28c7f4d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I've pulled in @rpkilby's suggested change: the simple use-case looks right; if we need more complex handling of other query expressions then we can look at that with test cases in hand.
Thanks all. @andrzej3393 Welcome aboard!
28c7f4d
to
6c197ee
Compare
@@ -85,6 +85,9 @@ def must_call_distinct(self, queryset, search_fields): | |||
opts = queryset.model._meta | |||
if search_field[0] in self.lookup_prefixes: | |||
search_field = search_field[1:] | |||
# Annotated fields do not need to be distinct | |||
if isinstance(queryset, models.QuerySet) and search_field in queryset.query.annotations: | |||
return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andrzej3393 , what if we have several search_fields
, and the first is an annotated field, and the others are m2m not annotated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Opened #7146.
Description
Fixes bug with searching in annotated fields.
refs #6094