问题描述:

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()
相关阅读:
Top