Serializer序列化组件高级使用
source的作用
1、改字段名字
2、可以跨表publish.email
3、可以执行方法(models.py该类中的方法)(source='test')test是Book表模型中的方法
在models.py文件中
from django.db import models
# Create your models here.
class Book(models.Model):
# title,price,pub_
# date,publish,author/Publish(name,email一对多),Author(name,age多对多,自动)
title = models.CharField(max_length=32)
price = models.DecimalField(max_digits=6,decimal_places=2)
pub_date = models.DateField(auto_now_add=True)
publish = models