Introduced new Document.objects.create, like django has. It creates a new object, saves it and returns the new object instance.
This commit is contained in:
parent
9f98025b8c
commit
13316e5380
@ -1,5 +1,6 @@
|
|||||||
from connection import _get_db
|
from connection import _get_db
|
||||||
|
|
||||||
|
import pprint
|
||||||
import pymongo
|
import pymongo
|
||||||
import re
|
import re
|
||||||
import copy
|
import copy
|
||||||
@ -414,6 +415,14 @@ class QuerySet(object):
|
|||||||
message = u'%d items returned, instead of 1' % count
|
message = u'%d items returned, instead of 1' % count
|
||||||
raise self._document.MultipleObjectsReturned(message)
|
raise self._document.MultipleObjectsReturned(message)
|
||||||
|
|
||||||
|
def create(self, **kwargs):
|
||||||
|
"""Create new object. Returns the saved object instance.
|
||||||
|
.. versionadded:: 0.4
|
||||||
|
"""
|
||||||
|
doc = self._document(**kwargs)
|
||||||
|
doc.save()
|
||||||
|
return doc
|
||||||
|
|
||||||
def first(self):
|
def first(self):
|
||||||
"""Retrieve the first object matching the query.
|
"""Retrieve the first object matching the query.
|
||||||
"""
|
"""
|
||||||
@ -667,7 +676,6 @@ class QuerySet(object):
|
|||||||
|
|
||||||
plan = self._cursor.explain()
|
plan = self._cursor.explain()
|
||||||
if format:
|
if format:
|
||||||
import pprint
|
|
||||||
plan = pprint.pformat(plan)
|
plan = pprint.pformat(plan)
|
||||||
return plan
|
return plan
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user