采纳答案成功!
向帮助你的同学说点啥吧!感谢那些助人为乐的人
就是根据数据库的数据数量生成这种json数据,应该怎么做
class Nj1(models.Model): fl1 = models.CharField(max_length=50, null=True, blank=True) class Meta: verbose_name = "年级1" verbose_name_plural = verbose_name def __str__(self): # 作用:在后台管理中显示每个不同数据的名称:self.username, py3为:__str__ return self.fl1class Nj2(models.Model): fl2 = models.CharField(max_length=50, null=True, blank=True) nj2 = models.ForeignKey(Nj1, null=True, blank=True, related_name='nj2') class Meta: verbose_name = "年级2" verbose_name_plural = verbose_name def __str__(self):#作用:在后台管理中显示每个不同数据的名称:self.username, py3为:__str__ return self.fl2class Nj3(models.Model): fl3 = models.ForeignKey(Nj2, null=True, blank=True, related_name='fl3') nj3 = models.CharField(max_length=50, null=True, blank=True) class Meta: verbose_name = "年级3" verbose_name_plural = verbose_name def __str__(self): # 作用:在后台管理中显示每个不同数据的名称:self.username, py3为:__str__ return self.nj3
这个要和数据库的model设计关联起来 你的model如何设计的?
class Nj1(models.Model): fl1 = models.CharField(max_length=50, null=True, blank=True) class Meta: verbose_name = "年级1" verbose_name_plural = verbose_name def __str__(self): # 作用:在后台管理中显示每个不同数据的名称:self.username, py3为:__str__ return self.fl1 class Nj2(models.Model): fl2 = models.CharField(max_length=50, null=True, blank=True) nj2 = models.ForeignKey(Nj1, null=True, blank=True, related_name='nj2') class Meta: verbose_name = "年级2" verbose_name_plural = verbose_name def __str__(self):#作用:在后台管理中显示每个不同数据的名称:self.username, py3为:__str__ return self.fl2 class Nj3(models.Model): fl3 = models.ForeignKey(Nj2, null=True, blank=True, related_name='fl3') nj3 = models.CharField(max_length=50, null=True, blank=True) class Meta: verbose_name = "年级3" verbose_name_plural = verbose_name def __str__(self): # 作用:在后台管理中显示每个不同数据的名称:self.username, py3为:__str__ return self.nj3
登录后可查看更多问答,登录/注册
Django REST framework课程视频,RESTFul API前后端分离开发
10.4k 1
4.3k 51
1.4k 19
977 19
1.7k 19