zoukankan      html  css  js  c++  java
  • [django]详情页列表页

    详情页列表页

    列表页展示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
    
    
  • 相关阅读:
    使用java实现面向对象 第一章
    深入.NET平台和C#编程笔记 第九章 文件操作
    MySQL_第七章
    MySQL_第八章
    MySQL_第五章
    MySQL_第四章
    MySQL_第三章
    MySQL_第二章
    MySQL_第一章
    S2_OOP第二章
  • 原文地址:https://www.cnblogs.com/iiiiiher/p/9667172.html
Copyright © 2011-2022 走看看