-
Notifications
You must be signed in to change notification settings - Fork 301
One-level select_related #395
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -403,7 +403,23 @@ class self.model, but as a class derived from self.model. We want to re-fetch | |||||||||||||||||||||||||||||||||||||||||
| **{(f"{pk_name}__in"): idlist} | ||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||
| # copy select related configuration to new qs | ||||||||||||||||||||||||||||||||||||||||||
| real_objects.query.select_related = self.query.select_related | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if self.query.select_related is False: | ||||||||||||||||||||||||||||||||||||||||||
| real_objects.query.select_related = False | ||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||
| concrete_model_name = real_concrete_class._meta.model_name | ||||||||||||||||||||||||||||||||||||||||||
| sub_model_names = set([m._meta.model_name for m in self.model.__subclasses__()]) | ||||||||||||||||||||||||||||||||||||||||||
| sub_model_names.remove(concrete_model_name) | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+411
to
+412
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| for sub_name in sub_model_names: | ||||||||||||||||||||||||||||||||||||||||||
| self.query.select_related.pop(sub_name, None) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if concrete_model_name in self.query.select_related: | ||||||||||||||||||||||||||||||||||||||||||
| real_objects.query.select_related = self.query.select_related[ | ||||||||||||||||||||||||||||||||||||||||||
| concrete_model_name | ||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||
| real_objects.query.select_related = self.query.select_related | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+407
to
+422
|
||||||||||||||||||||||||||||||||||||||||||
| for sub_name in sub_model_names: | |
| self.query.select_related.pop(sub_name, None) | |
| if concrete_model_name in self.query.select_related: | |
| real_objects.query.select_related = self.query.select_related[ | |
| concrete_model_name | |
| ] | |
| else: | |
| real_objects.query.select_related = self.query.select_related | |
| # Make a shallow copy to avoid mutating the original select_related dict | |
| select_related_copy = self.query.select_related.copy() | |
| for sub_name in sub_model_names: | |
| select_related_copy.pop(sub_name, None) | |
| if concrete_model_name in select_related_copy: | |
| real_objects.query.select_related = select_related_copy[ | |
| concrete_model_name | |
| ] | |
| else: | |
| real_objects.query.select_related = select_related_copy |
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.
Unnecessary list comprehension brackets. Use a set comprehension or generator expression directly:
sub_model_names = {m._meta.model_name for m in self.model.__subclasses__()}