У меня вопрос по поводу сериализатора django-rest-framework.Я хочу изменить формат поля моего набора запросов.
Я использовал django2.0 django-rest-framework3.9.2 python3.5.2
Модель:
class dataAll(models.Model):
name = models.CharField(max_length=16)
sale_count = models.IntegerField(blank=True, null=True)
ticket_price = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True)
ticket_price1 = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True)
ticket_price_sr = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True)
ticket_price_bed = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True)
ticket_price_air = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True)
ticket_price_add = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True)
statics_date = models.CharField(max_length=8)
class Meta:
managed = False
db_table = 'data_all'
serializerz:
class dataAllSerializer(serializers.ModelSerializer):
class Meta:
model = dataAll
fields = ('name',
'sale_count',
'ticket_price',
'ticket_price1',
'ticket_price_sr',
'ticket_price_bed',
'ticket_price_air',
'ticket_price_add',
# 'statics_date',
)
API:
@api_view(['GET','POST'])
def report_list(request, format=None):
snippets = dataAll.objects.filter(statics_date=date).values('bureau_name',
'sale_count',
'ticket_price',
'ticket_price1',
'ticket_price_sr',
'ticket_price_bed',
'ticket_price_air',
'ticket_price_add',)
report_count = snippets.count()
serializer = dataAllSerializer(snippets, many=True)
data = {'status': 200, 'page': 1, 'limit': 10, 'total': report_count, 'rows': {'item': serializer.data}}
return Response(data)
Я получил окончательные данные успешно, и ticket_price похож на 12345678.78
Но я хочу изменить формат данных на:
ticket_price = 1234.57
ticket_price1 = 1234.57
...
Как это сделать?
Спасибо!