diff options
| author | Nick Pope <nick@nickpope.me.uk> | 2021-09-21 00:49:16 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-07-27 10:06:24 +0200 |
| commit | 9dff316be41847c505ebf397e4a52a0a71e0acc4 (patch) | |
| tree | 1bf4412223b6c0467ae5107df9422ea1406b86d6 /django/contrib/contenttypes | |
| parent | 845667f2d1eb7063c568764a01fc9ee633ec5817 (diff) | |
Refs #32948, Refs #32946 -- Used Q.create() internally for dynamic Q() objects.
Node.create() which has a compatible signature with Node.__init__()
takes in a single `children` argument rather than relying in unpacking
*args in Q.__init__() which calls Node.__init__().
In addition, we were often needing to unpack iterables into *args and
can instead pass a list direct to Node.create().
Diffstat (limited to 'django/contrib/contenttypes')
| -rw-r--r-- | django/contrib/contenttypes/fields.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/django/contrib/contenttypes/fields.py b/django/contrib/contenttypes/fields.py index 193c2f2687..5b327b6ae4 100644 --- a/django/contrib/contenttypes/fields.py +++ b/django/contrib/contenttypes/fields.py @@ -627,17 +627,19 @@ def create_generic_related_manager(superclass, rel): queryset._add_hints(instance=instances[0]) queryset = queryset.using(queryset._db or self._db) # Group instances by content types. - content_type_queries = ( - models.Q( - (f"{self.content_type_field_name}__pk", content_type_id), - (f"{self.object_id_field_name}__in", {obj.pk for obj in objs}), + content_type_queries = [ + models.Q.create( + [ + (f"{self.content_type_field_name}__pk", content_type_id), + (f"{self.object_id_field_name}__in", {obj.pk for obj in objs}), + ] ) for content_type_id, objs in itertools.groupby( sorted(instances, key=lambda obj: self.get_content_type(obj).pk), lambda obj: self.get_content_type(obj).pk, ) - ) - query = models.Q(*content_type_queries, _connector=models.Q.OR) + ] + query = models.Q.create(content_type_queries, connector=models.Q.OR) # We (possibly) need to convert object IDs to the type of the # instances' PK in order to match up instances: object_id_converter = instances[0]._meta.pk.to_python |
