本文介绍了如何在Wagtail CMS中添加外部对象作为字段面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个预先存在的Django项目,我开始使用Wagtail驱动的应用程序。
在Django项目中,我有一个我需要在wagtail应用程序中提供的模型Map。



Django-project Map类在 model.py

  class Map(..):

Wagtail-app model.py:

  class Wagtail-appPage(Page):
main_image = models.ForeignKey(
'wagtailimages.Image',
null = True,
blank =
on_delete = models.SET_NULL,
related_name ='+'

map = models.ForeignKey(Map,related_name =map_set,null = True,blank = True)
date = models.DateField(Post date)
intro = models.CharField(max_length = 250)
body = RichTextField(blank = True)

content_panels = Page.content_panels + [
FieldPanel('date'),
FieldPanel('intro'),
FieldPanel('body',classname =full),
ImageChooserPanel (main_imag e'),
< MapChooserPanel>('map')
]

我的目标是添加一个拖放面板中的地图对象的可能性(例如MapChooserPanel())在wagtail / admin中,就像标准图像一样。



你将如何进行?听起来很难吗?我完全是Wagtail的新人。



提前感谢您提供的任何帮助。

解决方案

最简单的方法是将地图模型注册为,然后从您的页面引用。



祝你好运!


I've a pre-existing Django project where I started a Wagtail-driven app.In the Django project, I have a model Map which I need to make available also in the wagtail-app.

Django-project Map class in model.py

class Map(..):

Wagtail-app model.py:

class Wagtail-appPage(Page):
    main_image = models.ForeignKey(
       'wagtailimages.Image',
       null=True,
       blank=True,
       on_delete=models.SET_NULL,
       related_name='+'
    )
    map = models.ForeignKey(Map, related_name="map_set", null=True, blank=True)
    date = models.DateField("Post date")
    intro = models.CharField(max_length=250)
    body = RichTextField(blank=True)

    content_panels = Page.content_panels + [
        FieldPanel('date'),
        FieldPanel('intro'),
        FieldPanel('body', classname="full"),
        ImageChooserPanel('main_image'),
        <MapChooserPanel>('map')
    ]

My goal is to add the possibility to load map objects in a wagtail panel (for ex. MapChooserPanel()) in the wagtail/admin, as it happens for standard images.

How would you proceed? Does it sound very difficult? I'm totally new to Wagtail..

Thank you in advance for any help you will provide.

解决方案

The simplest approach is to register your Map model as a snippet, and then to reference it from your page with a SnippetChooserPanel.

Good luck!

这篇关于如何在Wagtail CMS中添加外部对象作为字段面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 10:11