django-location-field is a location field and widget for Django that makes it easy to store and display geographic points on a map.
To integrate it with Django Unfold, first install django-location-field according to its documentation, then add unfold.contrib.location_field to your INSTALLED_APPS setting before location_field.
# settings.py
INSTALLED_APPS = [
"unfold",
"unfold.contrib.location_field",
# ...
"location_field",
# ...
]
# admin.py
from django.contrib import admin
from unfold.admin import ModelAdmin
# Custom form where we override the location widget
class ExampleModelForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Change the widget for location field
self.fields["location"].widget = UnfoldAdminLocationWidget(
# base_fields = ["city"],
# zoom = 7
)
@admin.register(ExampleModelWithLocationField)
class ExampleModelAdmin(ModelAdmin):
form = ExampleModelForm # Override default changeform
© 2023 - 2026 Created by unfoldadmin.com. All rights reserved.