问题
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