外键插入方法
from django.shortcuts import render
from . import models
from django.http import HttpResponse
# Create your views here.
def index(request):
# 插入数据
# article = models.Article(title='abc',content='111')
# category = models.Category(name='最新文章')
# category.save()
# article.category = category
# article.save()
#读取数据
article = models.Article.objects.first()
print(article.category.name)
return HttpResponse('successful')
————————————————
版权声明:本文为CSDN博主「stu_xujin」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/xujin0/article/details/83552349
详细案例
外键快查询详解ww外键k查询wdjango框架学习:二十九.django 外键(ForeignKey)使用,查询 - 流水小哥 - 博客园
多对多,一对一详解