当前位置: 动力学知识库 > 问答 > 编程问答 >

django - Calling SerializerMethodField('function_name') for a DateTimeField

问题描述:

In the Django REST API Serializer I want to call a function that would return a DateTimeField by using SerializerMethodField. It works fine for integers but returns a null for a DateTimeField

网友答案:

Could you put in your code please ?
The following example works OK:

test_method_field = serializers.SerializerMethodField('get_datetime_field')

def get_datetime_field(self, obj):
    return datetime.datetime.now()
分享给朋友:
您可能感兴趣的文章:
随机阅读: