Overriding Admin widgets

353 views
Skip to first unread message

Andrew Barton

unread,
Jun 7, 2016, 6:25:52 PM6/7/16
to Wagtail support
Hi Everyone,

Really enjoying Wagtail and have decided to use it in a new project that has a mapping component. I normally use Django-Leaflet in my mapping apps and add the following code to admin.py to override the existing OpenLayer admin widet 

from django.contrib import admin
from leaflet.admin import LeafletGeoAdmin

from .models import WeatherStation

admin
.site.register(WeatherStation, LeafletGeoAdmin)


How do I do this with Wagtail? Currently, my model has this code for displaying fields in the admin page:

content_panels = Page.content_panels + [
       
FieldPanel('region', classname="full"),
       
FieldPanel('address', classname="full"),
       
FieldPanel('phone_number', classname="full"),
       
FieldPanel('website', classname="full"),
       
FieldPanel('geopoint', classname="full"),
   
]

I'm thinking I need to create/use something to replace FieldPanel but haven't figured it out yet.  Can't find this specific issue in the docs.

Many thanks for any assistance.

Andrew

Andrew Barton

unread,
Jun 15, 2016, 4:49:22 PM6/15/16
to Wagtail support
Bumping this. Anyone have any thoughts please?

Matthew Westcott

unread,
Jun 20, 2016, 12:28:24 PM6/20/16
to wag...@googlegroups.com
Hi Andrew,

Wagtail admin is a very different beast to the Django admin, so that's probably not the starting point to go for. Looking at the code snippets in the readme, it looks like your best bet is to pass a `widget` parameter to the FieldPanel:

from leaflet.forms.widgets import LeafletWidget

...

content_panels = Page.content_panels + [
FieldPanel('region', classname="full"),
FieldPanel('address', classname="full"),
FieldPanel('phone_number', classname="full"),
FieldPanel('website', classname="full"),
FieldPanel('geopoint', classname="full", widget=LeafletWidget()),
]

However, judging from the mention of {% leaflet_js %} / {% leaflet_css %} tags, Django-Leaflet is using a non-standard method to pull in the associated JS / CSS for the form field, so you might find that it's missing those when the form is rendered. If so, you may need to do some digging around to find out what JS / CSS files it requires, and insert them into the form using the `insert_editor_css` / `insert_editor_js` hooks, as per https://github.com/torchbox/wagtaildemo/blob/master/demo/wagtail_hooks.py .

Cheers,
- Matt
> --
> You received this message because you are subscribed to the Google Groups "Wagtail support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to wagtail+u...@googlegroups.com.
> To post to this group, send email to wag...@googlegroups.com.
> Visit this group at https://groups.google.com/group/wagtail.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/wagtail/1f49defe-9997-4771-9f72-41b0d277cc42%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Andrew Barton

unread,
Jun 20, 2016, 5:31:01 PM6/20/16
to Wagtail support
Thanks Matthew - I'll take a look at that approach and let you know what I find.

Thanks again.


On Tuesday, June 7, 2016 at 3:25:52 PM UTC-7, Andrew Barton wrote:
Reply all
Reply to author
Forward
0 new messages