You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import pytz
|
|
|
|
from rest_framework import serializers
|
|
|
|
from django.utils import timezone
|
|
|
|
from product.models import *
|
|
|
|
|
|
|
|
|
|
|
|
class ProjectSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = Project
|
|
|
|
fields = ('id', 'project_name', 'is_delete')
|
|
|
|
|
|
|
|
|
|
|
|
class PrdItemSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = PrdItem
|
|
|
|
fields = ('id', 'project', 'prd_version', 'prd_doc_link', 'prd_comment', 'is_delete', 'update_at')
|
|
|
|
|
|
|
|
def to_representation(self, instance):
|
|
|
|
rep = super().to_representation(instance)
|
|
|
|
if self.fields.get('update_at'):
|
|
|
|
# 根据你的字段配置动态获取需要转换的字段
|
|
|
|
original_time = getattr(instance, 'update_at')
|
|
|
|
local_tz = pytz.timezone('Asia/Shanghai')
|
|
|
|
rep['update_at'] = original_time.astimezone(local_tz).strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
return rep
|