I have a basic GeoDjango PointField:
point = models.PointField(srid=4326, null=True)
When using the admin, I would expect this to be saved in the database as (for example, London):
SRID=4326;POINT (-94.577597, 39.057294)
but instead, if I place the marker on London, I get:
SRID=4326;POINT (-19067.91721243037 6711435.410105047)
Where the longitude/latitude are way off.
I've tried manually setting the Point to the location:
obj.point = Point(-94.577597, 39.057294)
obj.save()
but the widget is then rendered way off.
So it seems that the wrong latitude and longitude are being saved to the field, or the wrong coordinate system is being used.
I've tried to manually override the widget to make sure the correct SRID is being used on the widget with:
class Meta:
model = models.MyModel
fields = "__all__"
widgets = {
'point': widgets.OSMWidget(attrs={
'map_srid': 4326,
'map_width': 800,
'map_height': 500,
'display_raw': True
})
}
but no luck.
I have all the dependencies for GeoDjango installed, I've enabled the postgis extension on my database and I the correct engine in use:
DATABASES['default']['ENGINE'] = 'django.contrib.gis.db.backends.postgis'
I also have added django.contrib.gis to INSTALLED_APPS. I'm using the default form widget, but I'm wondering might the widget be the problem?
OK, it seems I forgot to include the correct GeoDjango Admin class:
from django.contrib.gis import admin
from app import models
@admin.register(models.MyModel)
class MyAdmin(admin.OSMGeoAdmin):
pass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With