Ticket #8419: option2-create-patch.diff
File option2-create-patch.diff, 1.7 KB (added by , 16 years ago) |
---|
-
django/db/models/query.py
302 302 raise self.model.MultipleObjectsReturned("get() returned more than one %s -- it returned %s! Lookup parameters were %s" 303 303 % (self.model._meta.object_name, num, kwargs)) 304 304 305 def create(self, **kwargs):305 def create(self, force_insert=False, force_update=False, **kwargs): 306 306 """ 307 307 Creates a new object with the given kwargs, saving it to the database 308 308 and returning the created object. 309 310 The 'force_insert' and 'force_update' parameters can be used to insist 311 that the "create" must be an SQL insert or update (or equivalent for 312 non-SQL backends), respectively. Normally, they should not be set. 309 313 """ 310 314 obj = self.model(**kwargs) 311 obj.save( )315 obj.save(force_insert=force_insert, force_update=force_update) 312 316 return obj 313 317 314 318 def get_or_create(self, **kwargs): -
docs/ref/models/querysets.txt
560 560 561 561 are equivalent. 562 562 563 Note that if you specify the primary key value of an existing object then 564 ``create()`` acts as a one line shorthand for updating that object. 565 566 Advanced users who wish to force the ``create()`` method to perform an SQL 567 ``INSERT`` or an SQL ``UPDATE`` can pass the ``force_insert=True`` or 568 ``force_update=True`` parameters to ``create()``, just like ``save()`` 569 itself. 570 563 571 ``get_or_create(**kwargs)`` 564 572 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 565 573