from rest_framework.response import Response
1.Response本质也是继承了httpresponse,比httpResponse还强大,传入一个字典,列表可以序列化
2.会根据不同的请求客户端,返回不同的东西,如果是浏览器访问的话就返回一个页面,如果是手机端的话就返回数据
from django.db import models

# Create your models here.
class Book(models.Model):
    nid = models.AutoField(primary_key=True)
    name = models.CharField(max_length=32)
    price = models.DecimalField(max_digits=5, decimal_places=2)
    publish_date = models.DateField()

    publish = models.ForeignKey(to='Publish',to_field='nid',on_delete=models.CASCADE)
    authors=models.ManyToManyField(to='Author')
    def __str__(self):
        return self.name


class Author(models.Model):
    nid = models.AutoField(primary_key=True)
    name = models.CharField(max_length=32)
    age = models.IntegerField()




class Publish(models.Model):
    nid = models.AutoField(primary_key=True)
    name = models.CharField(max_length=32)
    city = models.CharField(max_length=32)
    email = models.EmailField()
models.py

相关文章:

  • 2022-12-23
  • 2022-02-13
  • 2021-06-11
  • 2021-10-26
  • 2022-12-23
  • 2021-12-25
  • 2021-10-28
  • 2021-12-12
猜你喜欢
  • 2021-07-05
  • 2021-10-22
  • 2022-02-16
  • 2021-05-21
  • 2021-05-24
  • 2021-12-18
  • 2021-05-17
相关资源
相似解决方案