mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Merged ManyRelatedObjectsDescriptor and ReverseManyRelatedObjectsDescriptor
and made all "many" related objects descriptors inherit from ForeignRelatedObjectsDescriptor.
This commit is contained in:
@@ -424,7 +424,7 @@ class ManyToManyTests(TestCase):
|
||||
def test_reverse_assign_with_queryset(self):
|
||||
# Ensure that querysets used in M2M assignments are pre-evaluated
|
||||
# so their value isn't affected by the clearing operation in
|
||||
# ReverseManyRelatedObjectsDescriptor.__set__. Refs #19816.
|
||||
# ManyRelatedObjectsDescriptor.__set__. Refs #19816.
|
||||
self.p1.article_set = [self.a1, self.a2]
|
||||
|
||||
qs = self.p1.article_set.filter(headline='Django lets you build Web apps easily')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from django.db.models.fields.related import (
|
||||
RECURSIVE_RELATIONSHIP_CONSTANT, ManyToManyField, ManyToManyRel,
|
||||
RelatedField, ReverseManyRelatedObjectsDescriptor,
|
||||
RECURSIVE_RELATIONSHIP_CONSTANT, ManyRelatedObjectsDescriptor,
|
||||
ManyToManyField, ManyToManyRel, RelatedField,
|
||||
create_many_to_many_intermediary_model,
|
||||
)
|
||||
from django.utils.functional import curry
|
||||
@@ -40,7 +40,7 @@ class CustomManyToManyField(RelatedField):
|
||||
super(CustomManyToManyField, self).contribute_to_class(cls, name, **kwargs)
|
||||
if not self.rel.through and not cls._meta.abstract and not cls._meta.swapped:
|
||||
self.rel.through = create_many_to_many_intermediary_model(self, cls)
|
||||
setattr(cls, self.name, ReverseManyRelatedObjectsDescriptor(self))
|
||||
setattr(cls, self.name, ManyRelatedObjectsDescriptor(self.rel))
|
||||
self.m2m_db_table = curry(self._get_m2m_db_table, cls._meta)
|
||||
|
||||
def get_internal_type(self):
|
||||
|
||||
Reference in New Issue
Block a user