【问题标题】:How to change the parent page?如何更改父页面?
【发布时间】:2019-07-16 12:14:41
【问题描述】:

我在管理单一视图中为文章页面提供了自定义视图和表单。在表单中,我有 HTML5 选择更改父级(部分)。如何在管理员编辑视图中更改父页面?我尝试使用已编辑的python wagtail.admin.views.pages.edit:

#wagtail code 
revision = page.save_revision(
    user=request.user,
    submitted_for_moderation=is_submitting,
)
#next I try to place my code
new_parent_page_id = request.POST.get('parent_page_id')
if int(new_parent_page_id) != parent.id:
    parent = SectionPage.objects.get(id=new_parent_page_id)
    page.move(parent, pos='last-child')
    page.save()

它不起作用

鹡鸰 2.4 版

【问题讨论】:

    标签: django python-3.x wagtail


    【解决方案1】:
    new_parent_page_id = request.POST.get('parent_page_id')
    if int(new_parent_page_id) != parent.id:
        parent = SectionPage.objects.get(id=new_parent_page_id)
        page.move(parent, pos='last-child')
        page = page.specific_class.objects.get(pk=page.pk)
    

    【讨论】:

    • 嘿马克西姆。关于如何/为什么对您有用的任何解释?我有代码,但它似乎没有将我的页面移动到新的父级。
    【解决方案2】:

    为了清楚起见,我能够使用以下代码使其工作:

    parent = Page.objects.find(...)
    
    child = Page.objects.find(...)
    
    child.move(parent, pos="last-child")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-08
      • 1970-01-01
      • 2022-08-05
      • 2014-01-12
      • 1970-01-01
      • 2016-10-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多