在views中添加 from django.shortcuts import render # Create your views here. from rest_framework.views import APIView from rest_framework.response import Response from app03.models import User from .serializers import * from rest_framework.viewsets import
DRF框架中链表数据通过ModelSerializer深度查询方法汇总 一.准备测试和理解准备 创建类 class Test1(models.Model): id = models.IntegerField(primary_key=True) test_2_id= models.ForeignKey(to='Test2',on_delete='id') #这里有的创建失败了哈哈忘了会自动补全id class Test2(models.Model): id = models.IntegerFiel
第一步: 学会使用ModelSerializer, 并且会使用ModelSerializer相互嵌套功能 1. goods.serializers.py from rest_framework import serializers from goods.models import Goods, GoodsCategory # 让goods的category字段全量显示 class CategorySerializer(serializers.ModelSerializer): class Met
转自:https://blog.csdn.net/l_vip/article/details/79156113 引言 serializers是什么?官网是这样的”Serializers allow complex data such as querysets and model instances to be converted to native Python datatypes that can then be easily rendered into JSON, XML or other