12345678910111213141516171819202122232425262728293031323334353637383940 |
- # coding=utf-8
- from django.conf import settings
- from rest_framework import serializers
- from utils.exceptions import CustomError
- from apps.base import Formater
- from apps.images.models import Images
- from .models import ProductOrder
- class ProductOrderSerializer(serializers.ModelSerializer):
- product_name = serializers.CharField(source='product.name', read_only=True)
- name = serializers.CharField(source='customer.name', read_only=True)
- customer_name = serializers.CharField(source='customer_address.name', read_only=True)
- customer_tel = serializers.CharField(source='customer_address.tel', read_only=True)
- area = serializers.CharField(source='customer_address.area', read_only=True)
- addr = serializers.CharField(source='customer_address.addr', read_only=True)
- status_text = serializers.CharField(source='get_status_display', read_only=True)
- create_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M', read_only=True)
- price = serializers.SerializerMethodField()
- amount = serializers.SerializerMethodField()
- def get_price(self, obj):
- return Formater.formatPriceShow(obj.price)
- def get_amount(self, obj):
- return Formater.formatAmountShow(obj.amount)
- class Meta:
- model = ProductOrder
- fields = '__all__'
- def validate(self, attrs):
- if 'price' in attrs:
- attrs['price'] = Formater.formatPrice(attrs['price'])
- return attrs
|