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

 

Django的外键使用

from django.db import models

# Create your models here.
class Category(models.Model):
    name = models.CharField(max_length=100)

class Article(models.Model):
    title = models.CharField(max_length=100)
    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

posted @ 2019-01-29 15:03  脚本小娃子  阅读(3605)  评论(0编辑  收藏  举报