我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用mongoengine.IntField()。
def setUp(self): """Setup.""" class ExclusionModel(gj.Document): to_json_exclude = db.StringField(exclude_to_json=True) from_json_exclude = db.IntField(exclude_from_json=True) json_exclude = db.StringField(exclude_json=True) required = db.StringField(required=True) self.cls = ExclusionModel self.test_data = [] for counter in range(3): data_el = { "to_json_exclude": ("To JSON Exclusion {}").format(counter), "from_json_exclude": counter, "json_exclude": ("JSON Exclusion {}").format(counter), "required": ("Required {}").format(counter) } model = self.cls(**data_el) model.save() self.test_data.append(data_el)
def setUp(self): """Setup.""" class ExclusionModel(gj.Document): to_json_exclude = db.StringField(exclude_to_json=True) from_json_exclude = db.IntField(exclude_from_json=True) json_exclude = db.StringField(exclude_json=True) required = db.StringField(required=True) self.cls = ExclusionModel self.data = { "to_json_exclude": "Hello", "from_json_exclude": 10234, "json_exclude": "Hi", "required": "World" } self.model = self.cls(**self.data)