标签:投票 cas htm shortcut har 类别 tail djang ext
列表页展示titile--这个模型的部分字段
详情页展示这个模型的所有字段
我想看下related_name这个从主表取子表数据
https://docs.djangoproject.com/en/2.1/intro/tutorial02/
polls/models.py
from django.db import models
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
polls/views.py
from django.shortcuts import get_object_or_404, render
from .models import Question
# ...
def detail(request, question_id):
question = get_object_or_404(Question, pk=question_id)
return render(request, 'polls/detail.html', {'question': question})
url
列表/详情
1.(文章)一个model情况
view
列表/详情
1.(文章)一个model情况
问题: titile
选项: choice: get_object_or_404
2.问题选项.(主表.次表_set)
model
related_name
标签:投票 cas htm shortcut har 类别 tail djang ext
原文地址:https://www.cnblogs.com/iiiiiher/p/9667172.html