improve _created status when switch collection and db
This commit is contained in:
		| @@ -477,7 +477,7 @@ class Document(BaseDocument): | |||||||
|             raise OperationError(message) |             raise OperationError(message) | ||||||
|         signals.post_delete.send(self.__class__, document=self) |         signals.post_delete.send(self.__class__, document=self) | ||||||
|  |  | ||||||
|     def switch_db(self, db_alias): |     def switch_db(self, db_alias, keep_created=True): | ||||||
|         """ |         """ | ||||||
|         Temporarily switch the database for a document instance. |         Temporarily switch the database for a document instance. | ||||||
|  |  | ||||||
| @@ -499,12 +499,12 @@ class Document(BaseDocument): | |||||||
|         self._get_collection = lambda: collection |         self._get_collection = lambda: collection | ||||||
|         self._get_db = lambda: db |         self._get_db = lambda: db | ||||||
|         self._collection = collection |         self._collection = collection | ||||||
|         self._created = True |         self._created = True if not keep_created else self._created | ||||||
|         self.__objects = self._qs |         self.__objects = self._qs | ||||||
|         self.__objects._collection_obj = collection |         self.__objects._collection_obj = collection | ||||||
|         return self |         return self | ||||||
|  |  | ||||||
|     def switch_collection(self, collection_name): |     def switch_collection(self, collection_name, keep_created=True): | ||||||
|         """ |         """ | ||||||
|         Temporarily switch the collection for a document instance. |         Temporarily switch the collection for a document instance. | ||||||
|  |  | ||||||
| @@ -525,7 +525,7 @@ class Document(BaseDocument): | |||||||
|             collection = cls._get_collection() |             collection = cls._get_collection() | ||||||
|         self._get_collection = lambda: collection |         self._get_collection = lambda: collection | ||||||
|         self._collection = collection |         self._collection = collection | ||||||
|         self._created = True |         self._created = True if not keep_created else self._created | ||||||
|         self.__objects = self._qs |         self.__objects = self._qs | ||||||
|         self.__objects._collection_obj = collection |         self.__objects._collection_obj = collection | ||||||
|         return self |         return self | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user