django外键以及主表和子表的相互查询

时间:2023-03-08 16:08:22
django外键以及主表和子表的相互查询

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