简体   繁体   English

在GeoDjango Admin中禁用Openlayers地图

[英]Disabling Openlayers map in GeoDjango Admin

I'm using Django 1.6 with Postgres/PostGIS (GeoDjango). 我正在使用Django 1.6和Postgres / PostGIS(GeoDjango)。 I noticed when I upgraded from 1.5 to 1.6 that I am no longer able to add spatial data using WKT through the admin page. 我注意到当我从1.5升级到1.6时,我无法再通过管理页面使用WKT添加空间数据。 Previously, I could paste in the WKT of the geometry that I wanted to display into a text box. 以前,我可以将要显示的几何体的WKT粘贴到文本框中。 Now, when I go to the admin page, a map is displayed which does allow me to edit the geometry, but I cannot add data. 现在,当我转到管理页面时,会显示一个允许我编辑几何图形的地图,但我无法添加数据。

Is there a simple fix that allows me to disable showing this map? 是否有一个简单的修复程序,允许我禁用显示此地图?

You can override the widget used in any admin form with formfield_overrides . 您可以使用formfield_overrides覆盖任何管理表单中使用的窗口小部件。

from https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_overrides 来自https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_overrides

ModelAdmin.formfield_overrides ModelAdmin.formfield_overrides

This provides a quick-and-dirty way to override some of the Field options for use in the admin. 这提供了一种快速而肮脏的方式来覆盖在管理中使用的一些Field选项。 formfield_overrides is a dictionary mapping a field class to a dict of arguments to pass to the field at construction time. formfield_overrides是一个字典,它将字段类映射到在构造时传递给字段的参数的字典。

So in your case, you'd want to override the lovely open layers map with a plain old text field. 所以在你的情况下,你想要用普通的旧文本字段覆盖可爱的开放图层地图。 The following would replace the maps with a text input for any PointField in the GeoModel model. 以下内容将使用GeoModel模型中任何PointField的文本输入替换地图。

from app.models import GeoModel
from django.forms.widgets import TextInput
from django.contrib.gis.db import models
from django.contrib import admin

class DirectAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.PointField: {'widget': TextInput }
    }

admin.site.register(GeoModel, DirectAdmin)

You might find a Textarea makes reading the WKT a lot easier, so change the second import to: 您可能会发现Textarea使得阅读WKT变得更加容易,因此将第二个导入更改为:

from django.forms.widgets import Textarea

And use that in the override instead of the TextInput: 并在覆盖中使用它而不是TextInput:

models.PointField: {'widget': Textarea }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM