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
| Attribute | Type | Description |
|---|---|---|
| gis_widget | class = OSMWidget | The widget class used to render geometry fields in the admin interface, defaulting to OSMWidget. |
| gis_widget_kwargs | dict = {} | 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
| Name | Type | Description |
|---|---|---|
| db_field | django.db.models.Field | The database field object being converted into a form field. |
| request | django.http.HttpRequest | The current HTTP request object, used for context-aware field generation. |
| **kwargs | dict | Additional keyword arguments passed to the form field constructor, such as labels or help text. |
Returns
| Type | Description |
|---|---|
django.forms.Field | A form field instance configured with a geographic widget if the field is a compatible GeometryField, otherwise the default field from the parent class. |