在admin中制作django-leaflet小部件

时间:2015-07-04 10:10:52

标签: django django-forms django-admin leaflet django-widget

如果我的模型可以在admin中制作django-leaflet小部件:

from django.contrib.gis.db import models as m
from djgeojson.fields import GeometryCollectionField

class Doc(m.Model):
    name = m.CharField()
    type = m.ForeignKey()
    geom = GeometryCollectionField()

如果我尝试:

管理员:

class DocAdmin(admin.ModelAdmin):
   form = f.DocGeometryForm
...

形式:

class DocGeometryForm(f.ModelForm):
    class Meta:
        model = m.Doc
        widgets = {
          'geom': LeafletWidget(),
        }

    class Media:
        css = {
            'all':('ext/leaflet/leaflet.css',)
        }
        js = [
            'ext/jquery/jquery.js',
            'ext/leaflet/leaflet.js',
        ]

获取:l.map.djangomap不是函数

1 个答案:

答案 0 :(得分:0)

您可以尝试这样的事情:

class MyAdmin(admin.ModelAdmin):

    @property
    def media(self):
        media = super(MyAdmin, self).media
        l = LeafletWidget()
        l.include_media = True
        return media + l.media