but it failed.
Because objects.create call QuerySet.create
@return_future
def create(self, callback, alias=None, **kwargs):
document = self.__klass__(**kwargs)
self.save(document=document, callback=callback, alias=alias)
def save(self, document, callback, alias=None):
if self.validate_document(document):
self.ensure_index(callback=self.indexes_saved_before_save(document, callback, alias=alias), alias=alias)
def indexes_saved_before_save(self, document, callback, alias=None):
def handle(*args, **kw):
self.update_field_on_save_values(document, document._id is not None)
doc = document.to_son()
if document._id is not None:
self.coll(alias).update({'_id': document._id}, doc, callback=self.handle_update(document, callback))
else:
self.coll(alias).insert(doc, callback=self.handle_save(document, callback))
return handle
and create method call save method. But in indexes_saved_before_save method, if document._id is not None, it will call update method, and cannot create an new instance.
I try to custom _id, like this:
but it failed. Because objects.create call QuerySet.create
and create method call save method. But in indexes_saved_before_save method, if document._id is not None, it will call update method, and cannot create an new instance.