MCPcopy
hub / github.com/django/django / set

Method set

django/contrib/contenttypes/fields.py:802–822  ·  view source on GitHub ↗
(self, objs, *, bulk=True, clear=False)

Source from the content-addressed store, hash-verified

800 _clear.alters_data = True
801
802 def set(self, objs, *, bulk=True, clear=False):
803 # Force evaluation of `objs` in case it's a queryset whose value
804 # could be affected by `manager.clear()`. Refs #19816.
805 objs = tuple(objs)
806
807 db = router.db_for_write(self.model, instance=self.instance)
808 with transaction.atomic(using=db, savepoint=False):
809 if clear:
810 self.clear()
811 self.add(*objs, bulk=bulk)
812 else:
813 old_objs = set(self.using(db).all())
814 new_objs = []
815 for obj in objs:
816 if obj in old_objs:
817 old_objs.remove(obj)
818 else:
819 new_objs.append(obj)
820
821 self.remove(*old_objs)
822 self.add(*new_objs, bulk=bulk)
823
824 set.alters_data = True
825

Callers 3

loadMethod · 0.45
saveMethod · 0.45
showAdminPopupFunction · 0.45

Calls 7

clearMethod · 0.95
addMethod · 0.95
removeMethod · 0.95
db_for_writeMethod · 0.45
allMethod · 0.45
usingMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected