![django外键以及主表和子表的相互查询 django外键以及主表和子表的相互查询](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
Django的外键使用
from django.db import models # Create your models here.
class Category(models.Model):
name = models.CharField(max_length=) class Article(models.Model):
title = models.CharField(max_length=)
content = models.TextField()
# 是由Category影响Article
category = models.ForeignKey('Category',on_delete=models.CASCADE,related_name="article_category")
https://blog.csdn.net/xujin0/article/details/83552349
通过主表查询子表、通过子表查询主表、字段related_name的作用:
https://blog.csdn.net/hpu_yly_bj/article/details/78939748