1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Refs #27674 -- Added tests for GISModelAdmin.gis_widget_kwargs.

This commit is contained in:
Alexander Filimonov 2021-12-17 20:40:22 +03:00 committed by Mariusz Felisiak
parent e8b4feddc3
commit 448145092c
2 changed files with 29 additions and 1 deletions

View File

@ -14,8 +14,20 @@ class City(models.Model):
return self.name
class CityAdminCustomWidgetKwargs(admin.GISModelAdmin):
gis_widget_kwargs = {
'attrs': {
'default_lat': 55,
'default_lon': 37,
},
}
site = admin.AdminSite(name='gis_admin_modeladmin')
site.register(City, admin.ModelAdmin)
site_gis = admin.AdminSite(name='gis_admin_gismodeladmin')
site_gis.register(City, admin.GISModelAdmin)
site_gis_custom = admin.AdminSite(name='gis_admin_gismodeladmin')
site_gis_custom.register(City, CityAdminCustomWidgetKwargs)

View File

@ -1,7 +1,7 @@
from django.contrib.gis.geos import Point
from django.test import SimpleTestCase, override_settings
from .models import City, site, site_gis
from .models import City, site, site_gis, site_gis_custom
@override_settings(ROOT_URLCONF='django.contrib.gis.tests.geoadmin.urls')
@ -57,3 +57,19 @@ class GeoAdminTest(SimpleTestCase):
class GISAdminTests(GeoAdminTest):
admin_site = site_gis # GISModelAdmin
def test_default_gis_widget_kwargs(self):
geoadmin = self.admin_site._registry[City]
form = geoadmin.get_changelist_form(None)()
widget = form['point'].field.widget
self.assertEqual(widget.attrs['default_lat'], 47)
self.assertEqual(widget.attrs['default_lon'], 5)
self.assertEqual(widget.attrs['default_zoom'], 12)
def test_custom_gis_widget_kwargs(self):
geoadmin = site_gis_custom._registry[City]
form = geoadmin.get_changelist_form(None)()
widget = form['point'].field.widget
self.assertEqual(widget.attrs['default_lat'], 55)
self.assertEqual(widget.attrs['default_lon'], 37)
self.assertEqual(widget.attrs['default_zoom'], 12)