Skip to main content

GeoModelAdminMixin

This class provides a mixin for model admin classes to integrate geographic widgets into the administrative interface. It automatically assigns a specialized GIS widget to geometry fields, provided the field dimensions are compatible with the widget's capabilities. Users can customize the widget type and its initialization arguments through class attributes.

Attributes

AttributeTypeDescription
gis_widgetclass = OSMWidgetThe widget class used to render geometry fields in the admin interface, defaulting to OSMWidget.
gis_widget_kwargsdict = {}A dictionary of keyword arguments passed to the gis_widget constructor during initialization.

Methods


formfield_for_dbfield()

@classmethod
def formfield_for_dbfield(
db_field: django.db.models.Field,
request: django.http.HttpRequest,
**kwargs: dict
) - > django.forms.Field

Overrides the default form field generation to inject a geographic widget for geometry fields that meet dimensionality requirements.

Parameters

NameTypeDescription
db_fielddjango.db.models.FieldThe database field object being converted into a form field.
requestdjango.http.HttpRequestThe current HTTP request object, used for context-aware field generation.
**kwargsdictAdditional keyword arguments passed to the form field constructor, such as labels or help text.

Returns

TypeDescription
django.forms.FieldA form field instance configured with a geographic widget if the field is a compatible GeometryField, otherwise the default field from the parent class.