Simplified RelatedManager._add_items() a bit.

Added early return in RelatedManager._add_items() to decrease an
indentation level.
This commit is contained in:
Baptiste Mispelon 2019-11-29 18:19:29 +01:00 committed by Mariusz Felisiak
parent 6c0341f127
commit c50839fccf
1 changed files with 39 additions and 40 deletions

View File

@ -1113,10 +1113,10 @@ def create_forward_many_to_many_manager(superclass, rel, reverse):
# source_field_name: the PK fieldname in join table for the source object
# target_field_name: the PK fieldname in join table for the target object
# *objs - objects to add. Either object instances, or primary keys of object instances.
through_defaults = through_defaults or {}
if not objs:
return
# If there aren't any objects, there is nothing to do.
if objs:
through_defaults = 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)
@ -1140,7 +1140,6 @@ def create_forward_many_to_many_manager(superclass, rel, reverse):
instance=self.instance, reverse=self.reverse,
model=self.model, pk_set=missing_target_ids, using=db,
)
# Add the ones that aren't there already.
self.through._default_manager.using(db).bulk_create([
self.through(**through_defaults, **{