Updates
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
from django.contrib.admin import (
|
||||
HORIZONTAL,
|
||||
VERTICAL,
|
||||
AdminSite,
|
||||
ModelAdmin,
|
||||
StackedInline,
|
||||
TabularInline,
|
||||
action,
|
||||
autodiscover,
|
||||
display,
|
||||
register,
|
||||
site,
|
||||
)
|
||||
from django.contrib.gis.admin.options import GISModelAdmin
|
||||
|
||||
__all__ = [
|
||||
"HORIZONTAL",
|
||||
"VERTICAL",
|
||||
"AdminSite",
|
||||
"ModelAdmin",
|
||||
"StackedInline",
|
||||
"TabularInline",
|
||||
"action",
|
||||
"autodiscover",
|
||||
"display",
|
||||
"register",
|
||||
"site",
|
||||
"GISModelAdmin",
|
||||
]
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,21 @@
|
||||
from django.contrib.admin import ModelAdmin
|
||||
from django.contrib.gis.db import models
|
||||
from django.contrib.gis.forms import OSMWidget
|
||||
|
||||
|
||||
class GeoModelAdminMixin:
|
||||
gis_widget = OSMWidget
|
||||
gis_widget_kwargs = {}
|
||||
|
||||
def formfield_for_dbfield(self, db_field, request, **kwargs):
|
||||
if isinstance(db_field, models.GeometryField) and (
|
||||
db_field.dim < 3 or self.gis_widget.supports_3d
|
||||
):
|
||||
kwargs["widget"] = self.gis_widget(**self.gis_widget_kwargs)
|
||||
return db_field.formfield(**kwargs)
|
||||
else:
|
||||
return super().formfield_for_dbfield(db_field, request, **kwargs)
|
||||
|
||||
|
||||
class GISModelAdmin(GeoModelAdminMixin, ModelAdmin):
|
||||
pass
|
||||
Reference in New Issue
Block a user