django resf 修改日期格式化
REST_FRAMEWORK = {
'DATETIME_FORMAT': '%Y-%m-%d %H:%M:%S', # 设置日期时间显示格式
}
REST_FRAMEWORK = {
'DATETIME_FORMAT': '%Y-%m-%d %H:%M:%S', # 设置日期时间显示格式
}
class ShareSerializer(serializers.ModelSerializer):
class Meta:
model = Share
# fields = '__all__'
exclude = ()
def to_representation(self, instance):
representation = super().to_representation(instance)
representation['created_at'] = instance.created_at.strftime("%Y-%m-%d %H:%M:%S")
representation['updated_at'] = instance.updated_at.strftime("%Y-%m-%d %H:%M:%S")
return representation