mirror of
https://github.com/django/django.git
synced 2025-10-29 16:46:11 +00:00
Added {{{Manager.create()}}} method to create and save an object in a single step.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3217 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -204,6 +204,15 @@ class QuerySet(object):
|
||||
raise self.model.DoesNotExist, "%s matching query does not exist." % self.model._meta.object_name
|
||||
assert len(obj_list) == 1, "get() returned more than one %s -- it returned %s! Lookup parameters were %s" % (self.model._meta.object_name, len(obj_list), kwargs)
|
||||
return obj_list[0]
|
||||
|
||||
def create(self, **kwargs):
|
||||
"""
|
||||
Create a new object with the given kwargs, saving it to the database
|
||||
and returning the created object.
|
||||
"""
|
||||
obj = self.model(**kwargs)
|
||||
obj.save()
|
||||
return obj
|
||||
|
||||
def get_or_create(self, **kwargs):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user