代码:
class ProjectSerializer(serializers.ModelSerializer): project_name = serializers.CharField(max_length=50, required=True, validators=[UniqueValidator(queryset=models.ProjectInformation.objects.all())] ) tester_charge = serializers.CharField(max_length=100, required=True) product_manager = serializers.CharField(max_length=100, required=True) project_description = serializers.CharField(max_length=200, allow_null=True, allow_blank=True) class Meta: model = models.ProjectInformation fields = "__all__" def to_representation(self, instance): data = super().to_representation(instance) create_time, update_time = data.get('create_time'), data.get("update_time") create_time_stamp = time.mktime(time.strptime(create_time, "%Y-%m-%d %H:%M:%S")) update_time_stamp = time.mktime(time.strptime(update_time, "%Y-%m-%d %H:%M:%S")) data.update({"create_time": create_time_stamp, "update_time": update_time_stamp}) return data
数据库:
返回效果: