1

i am have enabled everything needed to work with spatial data at the database and django setting level, my profile model has a default_location field that is a PointField. as shown below.

from django.contrib.gis import models

class Profile(models.Model):
    ...
    default_location = models.PointField()

i registered the profile model as an inline to be viewed and edited from within a User model (one-to-one relationship between user and profile).code shown below

class ProfileInline(StackedInline):
    model = models.Profile

class NewUserAdmin(admin.GISModelAdmin):
    gis_widget = OSMWidget
    inlines = [ProfileInline]

admin.site.unregister(models.User)
admin.site.register(models.User, NewUserAdmin)

however i keep getting a openlayer map in my django admin page

enter image description here

please can anyone suggest a fix to this. i need open street map because of it detailed street feature.

Brian Obot
  • 336
  • 4
  • 16

1 Answers1

1

You can use the django-leaflet package. By default an OpenStreetMap is displayed, and it also has better tools and interface.

After installing you need add leaflet to INSTALLED_APPS in settings.py.

Then you use LeafletGeoAdmin in your ModelAdmin in admin.py.

You can add some customizations by adding this to your settings.py:

LEAFLET_CONFIG = {
    'DEFAULT_CENTER': (39.694819, -8.130229),
    'DEFAULT_ZOOM': 6,
    'MAX_ZOOM': 20,
    'MIN_ZOOM':3,
    'SCALE': 'both'
}

More information here: https://django-leaflet.readthedocs.io/

Rafael Sá
  • 21
  • 4