Witryna31 paź 2024 · HeroInfo. objects. filter (hbook__id = 1) 例:查询id为1的英雄关联的图书信息。 h = HeroInfo. objects. get (id = 1) h. hbook 通过模型类查询: BookInfo. objects. filter (heroinfo__id = 1) 格式: 由一类的对象查询多类的时候: 一类的对象.多类名小写_set.all() #查询所用数据 由多类的对象 ... Witryna13 lis 2024 · #定义英雄模型类HeroInfo class HeroInfo (models.Model): GENDER_CHOICES = ( (0, 'male'), (1, 'female') ) hname = models.CharField (max_length=20, verbose_name='名称') hgender = models.SmallIntegerField (choices=GENDER_CHOICES, default=0, verbose_name='性别') hcomment = …
Python的关联查询_Cathy.wei的博客-CSDN博客_python 关联查询
Witryna27 mar 2024 · heroinfo_set = serializers.PrimaryKeyRelatedField(many=True,read_only=True) # 此字段将被序列化为关联对象的字符串表示方式(即__str__方法的返回值) heroinfo_set = serializers.StringRelatedField(read_only=True,many=True) # 使用关联对象的序列化 … Witryna18 cze 2024 · b.heroinfo_set.all () #查询出b图书中所有英雄人物的信息 八、后台管理: 1、本地化 语言和时区的本地化。 修改settings.py文件。 2、创建管理员 命令:python manage.py createsuperuser 3、注册模型类 在应用下的admin.py中注册模型类。 告诉djang框架根据注册的模型类来生成对应表管理页面。 b = BookInfo () 4、自定义管理 … marriott canada credit card offer
Django框架详解_吴大喜的博客-CSDN博客
Witryna22 cze 2024 · 变量.关联类_set.条件. 如 : BookInfo 是一 , Heroinfo 是多 . book = BookInfo.objects.get(id=1) book.heroinfo_set.all() 如果外键有取别名 : book.别名.条 … Witryna8 paź 2024 · 1.ModelSerialzer 在前一篇 DRF笔记(二):DRF框架初体验 中使用的其实就是ModelSerializer,在实际开发中使用的比较多的也是这个类。 可以参见代码仓库中book.serializers中的BookInfoSerializer和HeroInfoSerializer这两个类。 BookInfoSerializer代码如下: Witryna18 cze 2024 · (2)HeroInfo.objects.all() 4、关联操作. 查询出id为2的图书中所有英雄人物的信息。 b = BookInfo.objects.get(id=2) b.heroinfo_set.all() #查询出b图书中所有 … marriott california golf resorts