#27674 closed Cleanup/optimization (fixed)
Deprecate GeoModelAdmin and OSMGeoAdmin
| Reported by: | Claude Paroz | Owned by: | Mariusz Felisiak |
|---|---|---|---|
| Component: | GIS | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
The geometry fields now have default map widgets, so the need of gis-specific ModelAdmin classes is therefore less relevant.
However, the fact that ModelAdmin.formfield_for_dbfield is not documented does not help, so I'd suggest to document it first.
Change History (21)
comment:1 by , 9 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 9 years ago
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.
comment:3 by , 9 years ago
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.
comment:4 by , 5 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:6 by , 5 years ago
| Has patch: | set |
|---|
comment:7 by , 5 years ago
| Needs documentation: | set |
|---|---|
| Needs tests: | set |
| Patch needs improvement: | set |
comment:8 by , 4 years ago
| Needs documentation: | unset |
|---|---|
| Patch needs improvement: | unset |
| Triage Stage: | Accepted → Ready for checkin |
follow-up: 11 comment:10 by , 4 years ago
While looking into #33372 I noticed that there are two OpenLayersWidget classes:
django.contrib.gis.admin.widgets.OpenLayersWidget- this is used by the deprecatedGeoModelAdminclass and targets OpenLayers 2.xdjango.contrib.gis.forms.widgets.OpenLayersWidget- this is used as a parent toOSMWidget(used by the newGISModelAdmin) 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?)
comment:11 by , 4 years ago
| Needs tests: | unset |
|---|---|
| Resolution: | fixed |
| Status: | closed → new |
| Triage Stage: | Ready for checkin → Accepted |
Replying to Nick Pope:
While looking into #33372 I noticed that there are two
OpenLayersWidgetclasses:
django.contrib.gis.admin.widgets.OpenLayersWidget- this is used by the deprecatedGeoModelAdminclass and targets OpenLayers 2.xdjango.contrib.gis.forms.widgets.OpenLayersWidget- this is used as a parent toOSMWidget(used by the newGISModelAdmin) and targets OpenLayers 3.xDeprecation warnings were added for
GeoModelAdminandOSMGeoAdminas part of this ticket but.admin.widgets.OpenLayersWidgethas 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.htmlandgis/admin/osm.htmltemplates going away? (Not sure whether we add a documentation note?)
As far as I'm concerned, it is not needed.
comment:12 by , 4 years ago
| Has patch: | unset |
|---|
comment:14 by , 4 years ago
| Owner: | removed |
|---|---|
| Status: | new → assigned |
comment:15 by , 4 years ago
| Status: | assigned → new |
|---|
comment:18 by , 4 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Could you describe the relevance of
formfield_for_dbfieldin a bit more detail?