How to add an external object as a field panel in Wagtail CMS

烂漫一生 提交于 2019-12-25 14:12:41

问题


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.


回答1:


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!



来源:https://stackoverflow.com/questions/40593413/how-to-add-an-external-object-as-a-field-panel-in-wagtail-cms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!