GeoDjango PointField admin visualization

django-admin, geodjango

Solution

As Bibhas says you can override the widget used for the field, but the simple text input may not be usefull. So here is an example with a full widget that can be used for PointField of geodjango:

class LatLongWidget(forms.MultiWidget):
    """
    A Widget that splits Point input into latitude/longitude text inputs.
    """

    def __init__(self, attrs=None, date_format=None, time_format=None):
        widgets = (forms.TextInput(attrs=attrs),
                   forms.TextInput(attrs=attrs))
        super(LatLongWidget, self).__init__(widgets, attrs)

    def decompress(self, value):
        if value:
            return tuple(value.coords)
        return (None, None)

    def value_from_datadict(self, data, files, name):
        mylat = data[name + '_0']
        mylong = data[name + '_1']

        try:
            point = Point(float(mylat), float(mylong))
        except ValueError:
            return ''

        return point

And now you can override your model Admin:

from django.contrib.gis.db import models as geomodels
class CompanyAdmin(admin.ModelAdmin):
    list_display = ('name', 'approval', 'company_view',)
    list_filter = ('approval',)
    formfield_overrides = {
        geomodels.PointField: {'widget': LatLongWidget},
    }

Problem

I was wondering how I could change the default PointField visualization (the Openstreetmap) in admin so that I could enter simple latitude/longitude instead of select a point on the map? I looked at this one Latitude/longitude widget for pointfield? but could not get it working in any way in Django 1.6b4 Thanks

Original source

Related problems