首页 > 编程问答 >我可以将一个订单放在另一个订单中吗?

我可以将一个订单放在另一个订单中吗?

时间:2024-07-31 04:22:20浏览次数:6  
标签:python html django wagtail

我有这样的设置,我的 Orderable 允许我添加多张卡片来显示 pdf 文档。但是,有没有一种方法可以在 InLinePanel 中显示可订购的内容?

例如,我想要 20 张卡片,但在这些卡片中,pdf 的数量范围为 1 到 10 之间的任何数字。我想要这个,因为它使得pdf 很容易找到并且非常易于操作。


class ArchitectPage(Page):
    search_fields = Page.search_fields + [

    ]  # these are if adding a search to the website

    # content tab panels
    content_panels = Page.content_panels + [
        MultiFieldPanel(
            [InlinePanel('architect_pdf', max_num=20, min_num=0, label="architect doc")],
            heading="architect pdf"
        ),
    ]

    # what to call the panels on wagtail
    edit_handler = TabbedInterface([
        ObjectList(content_panels, heading='Content'),
        ObjectList(Page.promote_panels, heading='SEO'),
        ObjectList(Page.settings_panels, heading='Settings', classname='settings'),
        # classname settings adds the cog
    ])


class ArchitectDownloads(Orderable):
    page = ParentalKey(ArchitectPage, on_delete=models.CASCADE, related_name='architect_pdf')
    architect_pdf = models.ForeignKey(
        'wagtaildocs.Document',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+'
    )
    image = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.CASCADE,
        related_name='+'
    )
    caption = models.CharField(blank=True, max_length=250)

    panels = [
        ImageChooserPanel('image'),
        FieldPanel('caption'),
        DocumentChooserPanel('architect_pdf'),
    ]
{% for download in page.architect_pdf.all %} 

            <div class="document line-up-card">
                <div class="w3-card-4 w3-margin w3-white" data-aos="fade-down">


                    {% image download.image fill-150x150-c100 %}
                    {% with doc=download.architect_pdf %} 

                        <div class="w3-container">
                            {{ doc.title }}
                        </div>

                    {% endwith %}

                  <hr>
                    <p id="caption">{{ download.caption }}</p>

                    {% with doc=download.architect_pdf %}

                        <div class="download">
                            <a href="{{ doc.url }}" class="smooth-over-button noDecoration">
                                <i class="fa fa-download"></i>
                                <p class="btn-txt">PDF</p>
                            </a>

                        </div>

                    {% endwith %}


                </div>
            </div>

{% endfor %}

card view


虽然你不能直接在 Wagtail 中将一个 Orderable 嵌套在另一个 Orderable 中,但你可以通过调整数据模型和使用 InlinePanels 来实现你想要的结果。

以下是如何做到这一点:

1. 修改你的模型:

  • 创建一个新的模型来代表一组 PDF 文档。
  • 将现有的 ArchitectDownloads 模型重命名为 PDFDocument ,并将其与新的组模型相关联。
class ArchitectPage(Page):
    # ... 你的现有代码 ...

class PDFDocumentGroup(Orderable):
    page = ParentalKey(ArchitectPage, on_delete=models.CASCADE, related_name='pdf_document_groups')
    heading = models.CharField(max_length=255, blank=True)

    panels = [
        FieldPanel('heading'),
        InlinePanel('pdf_documents', label="PDF Documents", max_num=10, min_num=1),
    ]

class PDFDocument(Orderable):
    group = ParentalKey(PDFDocumentGroup, on_delete=models.CASCADE, related_name='pdf_documents')
    pdf_file = models.ForeignKey(
        'wagtaildocs.Document',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+'
    )
    image = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.CASCADE,
        related_name='+'
    )
    caption = models.CharField(blank=True, max_length=250)

    panels = [
        ImageChooserPanel('image'),
        FieldPanel('caption'),
        DocumentChooserPanel('pdf_file'),
    ]

2. 更新你的模板:

  • 迭代 pdf_document_groups ,然后在每个组内迭代 pdf_documents
{% for group in page.pdf_document_groups.all %}
    <h3>{{ group.heading }}</h3>

    {% for download in group.pdf_documents.all %}
        <div class="document line-up-card">
            <div class="w3-card-4 w3-margin w3-white" data-aos="fade-down">
                {% image download.image fill-150x150-c100 %}
                <div class="w3-container">
                    {{ download.pdf_file.title }}
                </div>
                <hr>
                <p id="caption">{{ download.caption }}</p>
                <div class="download">
                    <a href="{{ download.pdf_file.url }}" class="smooth-over-button noDecoration">
                        <i class="fa fa-download"></i>
                        <p class="btn-txt">PDF</p>
                    </a>
                </div>
            </div>
        </div>
    {% endfor %}
{% endfor %}

通过这种方式,你可以在每个 PDFDocumentGroup 中拥有 1 到 10 个 PDFDocument ,并使用 Wagtail 的 Orderable 功能轻松地对组和组内的文档进行排序。

标签:python,html,django,wagtail
From: 62812231

相关文章

  • python函数:带星号的参数一个接一个
    我想知道为什么定义以下函数被认为是好的。deffoo(*x,y):pass据我所知,现在有调用此函数的方法,因为它总是缺少y的值。(如果我错了,请纠正我。)这有什么我不知道的用处吗?你说得对,在Python中定义一个像deffoo(*x,y):...这样的函数,在试图以常规方......
  • 基于遗传(GA)、粒子群(PSO)、模拟退火(SA)、禁忌搜索(ST)、蚁群算法(ACO)、自自组织神
        ......
  • 10个append()函数在Python程序开发中的创新应用
    文末赠免费精品编程资料~~在Python编程的世界里,append()函数是列表操作中最常见的方法之一。它允许我们在列表的末尾添加一个元素,这一简单的功能却能激发无限的创造力。今天,我们将探讨append()函数在Python程序开发中的10种创新应用,从基本用法到高级技巧,逐步深入。1.构......
  • 全网最适合入门的面向对象编程教程:28 类和对象的Python实现-Python编程原则、哲学和规
    全网最适合入门的面向对象编程教程:28类和对象的Python实现-Python编程原则、哲学和规范大汇总摘要:本文主要介绍了在使用Python进行面向对象编程时,Python异常处理的原则-“请求谅解,而非许可”,以及软件设计和Python的编程原则,同时介绍了PEP8规范。原文链接:FreakStud......
  • python生成器
    一前言环境:python3.10win10二生成器1关于生成器先看一个例子    定义了一个函数,当我们运行该函数时,并未像普通函数那样执行函数体内的代码    从其中的英文可知,执行函数得到了一个生成器对象,这个生成器对象也叫做generatoriterator(生成器迭代器),generatorit......
  • 生成MySQL-oracle-SQL server数据字典(附Python代码)
    生成数据字典,早年写的,请注意新的版本变化。(1)MySQL元数据SQLUSEinformation_schema;#取出库和表。select  TABLE_SCHEMAAS'数据库名称',  TABLE_NAMEAS'表名',  TABLE_TYPEAS'表类型',  ROW_FORMATAS'行格式',  ENGINEAS'数据库引擎',  TABL......
  • Python - Method Resolution Order (MRO)
    TheorderinwhichPythonsearchesforattributesinbaseclassesiscalledmethodresolutionorder(MRO).Itgivesalinearizedpathforaninheritancestructure.PythoncomputesanMROforeveryclassinthehierarchy;thisMROiscomputedusingthe‘C3......
  • 计算机毕业设计选题推荐-零食批发商仓库管理系统-Java/Python项目实战
    ✨作者主页:IT研究室✨个人简介:曾从事计算机专业培训教学,擅长Java、Python、微信小程序、Golang、安卓Android等项目实战。接项目定制开发、代码讲解、答辩教学、文档编写、降重等。☑文末获取源码☑精彩专栏推荐⬇⬇⬇Java项目Python项目安卓项目微信小程序项目......
  • 【自动化测试必学语言】python:语言基础
    目录Python介绍语言的分类注释单行注释多行注释变量定义变量使用变量变量名的命名规范数据类型数字类型非数字类型type()函数input输入print输出格式化输出快捷键(小操作)运算符算术运算符 比较运算符Python介绍作者:吉多·范罗苏姆(Guidov......
  • Python基础知识笔记——常用函数
    一、range()函数range()函数用于生成一个整数序列。它通常用于循环结构中,例如for循环,以提供循环的迭代次数。range()函数可以有1到3个参数。#range(start,stop,step)range(2,6,2)#生成从2开始,到6结束(不包括6),步长为2的一串数字#参数指定不完全时,默认从0开始,步长......