madisona / django-google-maps

Using the Google Maps API with django model admin
BSD 2-Clause "Simplified" License
281 stars 99 forks source link

Making geolocation read only returns world map #4

Closed orschiro closed 11 years ago

orschiro commented 11 years ago

djangoGoogleMaps Hello,

I followed your suggestion and put geolocation into read only.

from locations.models import Container
from django.contrib import admin
from django_google_maps import widgets as map_widgets
from django_google_maps import fields as map_fields

class ContainerAdmin(admin.ModelAdmin):
    formfield_overrides = {
        map_fields.AddressField: {'widget': map_widgets.GoogleMapsAddressWidget},
    }
    readonly_fields=('geolocation',)

admin.site.register(Container, ContainerAdmin)

However, now I only see the world map in the admin but no longer the exact address as given by AddressField.

How can I fix that?

Regards

Robert

madisona commented 11 years ago

That's because when you declare a readonly field like that, django makes it not a real form field and the location never gets saved. I do it like this in the admin:

formfield_overrides = { map_fields.GeoLocationField: {'widget': widgets.TextInput(attrs={'readonly': 'readonly'})}, }

This forces the html to be readonly, but the form data still stays and gets posted.

I apologize for the slow reply, I was on vacation.

tatvaparthesh commented 5 years ago

What does map_fields.GeoLocationField actually is?