Is there any difference between below 2 cases in Django ORM operation? Will there be any performance gains etc?
obj.manytomanyfield.clear()
obj.manytomanyfield.add(1,2,3,4,5)
and
obj.manytomanyfield.set([1,2,3,4,5])
Is there any difference between below 2 cases in Django ORM operation? Will there be any performance gains etc?
obj.manytomanyfield.clear()
obj.manytomanyfield.add(1,2,3,4,5)
and
obj.manytomanyfield.set([1,2,3,4,5])
From the doc, set()-Django doc
This method accepts a
clearargument to control how to perform the operation. IfFalse(the default), the elements missing from the new set are removed usingremove()and only the new ones are added. Ifclear=True, theclear()method is called instead and the whole set is added at once.
Which means,
obj.manytomanyfield.clear()
obj.manytomanyfield.add(1,2,3,4,5)
is equal to
obj.manytomanyfield.set([1,2,3,4,5], clear=True)