However, the fact that `ModelAdmin.formfield_for_dbfield` is not
documented does not help, so I'd suggest to document it first.
--
Ticket URL: <https://code.djangoproject.com/ticket/27674>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* stage: Unreviewed => Accepted
Comment:
Could you describe the relevance of `formfield_for_dbfield` in a bit more
detail?
--
Ticket URL: <https://code.djangoproject.com/ticket/27674#comment:1>
Comment (by Claude Paroz):
Sure. The typical example is to be sure all geometry widgets use a
specific map widget, or specific map widget attributes.
With `formfield_overrides`, you'd have to specify all field types:
{{{
class MyModelAdmin(admin.ModelAdmin):
formfield_overrides = {
models.PointField: {'widget': MyCustomMapWidget},
models.PolygonField: {'widget': MyCustomMapWidget},
models.LineField: {'widget': MyCustomMapWidget},
models.MultiPointField: {'widget': MyCustomMapWidget},
...
}
}}}
which is not nice if you have many geometry field types in your project. I
think it's a case where `formfield_for_dbfield` is handy:
{{{
class MyModelAdmin(admin.ModelAdmin):
def formfield_for_dbfield(self, db_field, request, **kwargs):
if isinstance(db_field, models.GeometryField) and db_field.dim <
3:
kwargs['widget'] = OSMWidget(default_lon=151, default_lat=-33)
return db_field.formfield(**kwargs)
else:
return super(GeoModelAdmin,
self).formfield_for_dbfield(db_field, request, **kwargs)
}}}
An alternative would be to still provide a GIS admin utility (subclass or
mixin) which sets the same map widget for all geometry fields, like the
current `GeoModelAdmin.get_map_widget()`. Basically the current code
without all the boiler plate code copying class attributes to widget
attributes.
--
Ticket URL: <https://code.djangoproject.com/ticket/27674#comment:2>
Comment (by Tim Graham):
Another idea: I like to see this sort of issue solved at the form level,
if possible, to allow reusing the solution outside the admin.
--
Ticket URL: <https://code.djangoproject.com/ticket/27674#comment:3>
* owner: nobody => Giannis Adamopoulos
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/27674#comment:4>
Comment (by Giannis Adamopoulos):
[https://github.com/django/django/pull/13733 Submitted PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/27674#comment:5>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/27674#comment:6>
* needs_better_patch: 0 => 1
* needs_tests: 0 => 1
* needs_docs: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/27674#comment:7>
* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
* needs_docs: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/27674#comment:8>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"4555aa0a489cb9dcf764edf12339097cdfa5ff84" 4555aa0a]:
{{{
#!CommitTicketReference repository=""
revision="4555aa0a489cb9dcf764edf12339097cdfa5ff84"
Fixed #27674 -- Deprecated GeoModelAdmin and OSMGeoAdmin.
Co-authored-by: Mariusz Felisiak <felisiak...@gmail.com>
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27674#comment:9>
Comment (by Nick Pope):
While looking into #33372 I noticed that there are two `OpenLayersWidget`
classes:
- `django.contrib.gis.admin.widgets.OpenLayersWidget` - this is used by
the deprecated `GeoModelAdmin` class and targets OpenLayers 2.x
- `django.contrib.gis.forms.widgets.OpenLayersWidget` - this is used as a
parent to `OSMWidget` (used by the new `GISModelAdmin`) and targets
OpenLayers 3.x
Deprecation warnings were added for `GeoModelAdmin` and `OSMGeoAdmin` as
part of this ticket but `.admin.widgets.OpenLayersWidget` has no warning.
Do we need to add one?
Do we also need to warn about `gis/admin/openlayers.html` and
`gis/admin/osm.html` templates going away? (Not sure whether we add a
documentation note?)
--
Ticket URL: <https://code.djangoproject.com/ticket/27674#comment:10>
* status: closed => new
* resolution: fixed =>
* needs_tests: 1 => 0
* stage: Ready for checkin => Accepted
Comment:
Replying to [comment:10 Nick Pope]:
> While looking into #33372 I noticed that there are two
`OpenLayersWidget` classes:
>
> - `django.contrib.gis.admin.widgets.OpenLayersWidget` - this is used by
the deprecated `GeoModelAdmin` class and targets OpenLayers 2.x
> - `django.contrib.gis.forms.widgets.OpenLayersWidget` - this is used as
a parent to `OSMWidget` (used by the new `GISModelAdmin`) and targets
OpenLayers 3.x
>
> Deprecation warnings were added for `GeoModelAdmin` and `OSMGeoAdmin` as
part of this ticket but `.admin.widgets.OpenLayersWidget` has no warning.
Do we need to add one?
Agreed, we can deprecate
`django.contrib.gis.admin.widgets.OpenLayersWidget` in Django 4.1 and
remove it in 5.0. Let's reopen.
> Do we also need to warn about `gis/admin/openlayers.html` and
`gis/admin/osm.html` templates going away? (Not sure whether we add a
documentation note?)
As far as I'm concerned, it is not needed.
--
Ticket URL: <https://code.djangoproject.com/ticket/27674#comment:11>
* has_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/27674#comment:12>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"448145092c23074b5c3b6c0502358c1d7eface8b" 44814509]:
{{{
#!CommitTicketReference repository=""
revision="448145092c23074b5c3b6c0502358c1d7eface8b"
Refs #27674 -- Added tests for GISModelAdmin.gis_widget_kwargs.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27674#comment:13>
* owner: Giannis Adamopoulos => (none)
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/27674#comment:14>
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/27674#comment:15>
* owner: (none) => Mariusz Felisiak
* status: new => assigned
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/15624 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/27674#comment:16>
Comment (by GitHub <noreply@…>):
In [changeset:"eeb0bb63795f7500156abaed2a94aae681a9fc4a" eeb0bb6]:
{{{
#!CommitTicketReference repository=""
revision="eeb0bb63795f7500156abaed2a94aae681a9fc4a"
Refs #27674 --- Deprecated django.contrib.gis.admin.OpenLayersWidget.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27674#comment:17>
* status: assigned => closed
* resolution: => fixed
--
Ticket URL: <https://code.djangoproject.com/ticket/27674#comment:18>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"ce7b4f39e3635bfcaa2cec84d5da93c1dedcaa9c" ce7b4f3]:
{{{
#!CommitTicketReference repository=""
revision="ce7b4f39e3635bfcaa2cec84d5da93c1dedcaa9c"
Refs #27674 -- Removed django.contrib.gis.admin.OpenLayersWidget per
deprecation timeline.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27674#comment:20>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"4982958ec0c359908566fc1f34ef71297ea4337d" 4982958]:
{{{
#!CommitTicketReference repository=""
revision="4982958ec0c359908566fc1f34ef71297ea4337d"
Refs #27674 -- Removed GeoModelAdmin and OSMGeoAdmin per deprecation
timeline.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27674#comment:19>