1. 程式人生 > >[django]詳情頁列表頁

[django]詳情頁列表頁

取數據 pro 表數據 har info gop text doc 小結

詳情頁列表頁

技術分享圖片

技術分享圖片

技術分享圖片

列表頁展示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})

技術分享圖片

類別 tag 文章/出版社 作者 圖書

技術分享圖片

技術分享圖片

小結

url
    列表/詳情
        1.(文章)一個model情況
view
    列表/詳情
        1.(文章)一個model情況
            問題: titile
            選項: choice: get_object_or_404
        2.問題選項.(主表.次表_set)
model
    related_name

[django]詳情頁列表頁