SlugRelatedField自动创建关联表对象
例如有以下模型类,此处外键设置时blank和null约束条件必须设为True
class Book(models.Model):
book_id = models.CharField(max_length=150)
name = models.CharField(max_length=50)
class Meta:
db_table = 'book'
class Characters(models.Model):
name = models.CharField(max_length=50)
books =models.ForeignKey('Book',related_name='Characters',on_delete=models.CASCADE