1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #31046 -- Allowed RelatedManager.add()/create()/set() to accept callable values in through_defaults.

This commit is contained in:
Baptiste Mispelon
2019-11-29 17:54:03 +01:00
committed by Mariusz Felisiak
parent c50839fccf
commit 26cab4e8c1
4 changed files with 71 additions and 4 deletions

View File

@@ -68,6 +68,7 @@ from django.db import connections, router, transaction
from django.db.models import Q, signals
from django.db.models.query import QuerySet
from django.db.models.query_utils import DeferredAttribute
from django.db.models.utils import resolve_callables
from django.utils.functional import cached_property
@@ -1116,7 +1117,7 @@ def create_forward_many_to_many_manager(superclass, rel, reverse):
if not objs:
return
through_defaults = through_defaults or {}
through_defaults = dict(resolve_callables(through_defaults or {}))
target_ids = self._get_target_ids(target_field_name, objs)
db = router.db_for_write(self.through, instance=self.instance)
can_ignore_conflicts, must_send_signals, can_fast_add = self._get_add_plan(db, source_field_name)