Skip to content
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

Support sorting cluster by related model fields #131

Closed
wants to merge 2 commits into from
Closed

Support sorting cluster by related model fields #131

wants to merge 2 commits into from

Conversation

rjmackay
Copy link

  • Support sorting a cluster by a related model field ie. vocalist__name
  • Support sorting a cluster by a related model field ie. vocalist (where vocalist is a FK)
  • Add tests

I'm not 100% sure how well this performs if those fields aren't loaded from the DB. I think potentially it'll hit the DB in an n+1 query.

Fixes #45

@rjmackay
Copy link
Author

Ah looks like tests failed because I used f-strings which don't existing in Python 3.5. Happy to fix that but I'd love a review of the general approach first.

@rjmackay
Copy link
Author

rjmackay commented Nov 15, 2020

@gasman any update on getting this reviewed?

@ababic
Copy link
Contributor

ababic commented Dec 13, 2021

Hi @rjmackay. Since we need to be able to do something similar for filter strings, I thought it might be good to solve this in a more generic way. In #148, I've gone with an extract_field_value() function that can be reused here, as well as in the various value checking methods in queryset.py.

I haven't gotten round to writing tests yet, but what you've done here looks good. Do you mind if I copy that bit? Also, any thoughts you have on #148 would be appreciated.

@gasman
Copy link
Contributor

gasman commented Mar 4, 2022

Implemented in #148.

@gasman gasman closed this Mar 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sort_by_fields() fails when model is ordered through a foreign key
3 participants