本文整理汇总了Python中mongoengine.fields.DateTimeField方法的典型用法代码示例。如果您正苦于以下问题:Python fields.DateTimeField方法的具体用法?Python fields.DateTimeField怎么用?Python fields.DateTimeField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongoengine.fields
的用法示例。
在下文中一共展示了fields.DateTimeField方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_regular_fields
# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import DateTimeField [as 别名]
def test_regular_fields(self):
"""
Model fields should map to their equivelent serializer fields.
"""
class TestSerializer(DocumentSerializer):
class Meta:
model = RegularModel
fields = '__all__'
regex_repr = "re.compile('^valid_regex')"
expected = dedent("""
TestSerializer():
id = ObjectIdField(read_only=True)
str_field = CharField(required=False)
str_regex_field = RegexField(regex=%s, required=False)
url_field = URLField(required=False)
email_field = EmailField(required=False)
int_field = IntegerField(required=False)
long_field = IntegerField(required=False)
float_field = FloatField(required=False)
boolean_field = BooleanField(required=False)
nullboolean_field = NullBooleanField(required=False)
date_field = DateTimeField(required=False)
complexdate_field = DateTimeField(required=False)
uuid_field = UUIDField(required=False)
id_field = ObjectIdField(required=False)
decimal_field = DecimalField(decimal_places=2, max_digits=65536, required=False)
custom_field = DocumentField(model_field=<tests.test_basic.CustomField: custom_field>, required=False)
""" % regex_repr)
assert repr(TestSerializer()) == expected
示例2: test_meta_exclude
# 需要导入模块: from mongoengine import fields [as 别名]
# 或者: from mongoengine.fields import DateTimeField [as 别名]
def test_meta_exclude(self):
"""
Serializer should respect Meta.exclude
"""
class TestSerializer(DocumentSerializer):
class Meta:
model = RegularModel
exclude = ('decimal_field', 'custom_field')
regex_repr = "re.compile('^valid_regex')"
expected = dedent("""
TestSerializer():
id = ObjectIdField(read_only=True)
str_field = CharField(required=False)
str_regex_field = RegexField(regex=%s, required=False)
url_field = URLField(required=False)
email_field = EmailField(required=False)
int_field = IntegerField(required=False)
long_field = IntegerField(required=False)
float_field = FloatField(required=False)
boolean_field = BooleanField(required=False)
nullboolean_field = NullBooleanField(required=False)
date_field = DateTimeField(required=False)
complexdate_field = DateTimeField(required=False)
uuid_field = UUIDField(required=False)
id_field = ObjectIdField(required=False)
""" % regex_repr)
assert repr(TestSerializer()) == expected