将默认GeoModelAdmin更改为OSMGeoAdmin

时间:2017-10-18 07:23:33

标签: django geodjango wagtail

我试图像往常一样天真地将它添加到admin.py

from django.contrib.gis import admin 
from project.models import ProjectMap

admin.site.register(ProjectMap, admin.OSMGeoAdmin)

我尝试指定小部件:

content_panels = Page.content_panels + [ 
    FieldPanel('location', widget='django.contrib.gis.forms.widgets.OSMWidget'),
]

但是它显示了GeoModelAdmin的默认卫星图像。

以下是我正在使用的基本模型。

class ProjectPage(Page):
    date = models.DateField("Post date", null=True)
    body = RichTextField(blank=True)

    def main_image(self):
        gallery_item = self.gallery_images.first()
        if gallery_item:
            return gallery_item.image
        else:
            return None

    search_fields = Page.search_fields + [
        index.SearchField('body'),
    ]

    content_panels = Page.content_panels + [
        MultiFieldPanel([
            FieldPanel('date'),
        ], heading="Project information"),
        MultiFieldPanel([
            FieldPanel('body', classname="full"),
        ], heading='Project'),
        InlinePanel('gallery_images', label="Gallery images"),
        InlinePanel('project_map', label="Project location")
    ]


class ProjectMap(Orderable):
    page = ParentalKey(ProjectPage, related_name='project_map')
    city = models.CharField(blank=True, max_length=250)
    address = models.CharField(blank=True, max_length=250)
    country = models.CharField(blank=True, max_length=250)
    location = PointField(blank=True, null=True)

    content_panels = Page.content_panels + [
        MultiFieldPanel([
            FieldPanel('city'),
            FieldPanel('address'),
            FieldPanel('country'),
            FieldPanel('location'),
        ], heading="Location")
    ]

我所遵循的文件:

1 个答案:

答案 0 :(得分:0)

@gasman是正确的!

如果你看一下关于specifying widgets的Django文档,你会看到一个对象被传递而不是一个字符串:

from django.contrib.gis.forms.widgets import OSMWidget

content_panels = Page.content_panels + [FieldPanel('location', widget=OSMWidget),]