Commits

Mikhail Korobov committed 2cf5531

Basic map widget

Comments (0)

Files changed (2)

 * latitude
 * geocode_error - True if geocoder wasn't able to handle the address
 
+Admin address preview
+=====================
+
+django-easy-maps provides basic widget that displays a map under the address
+field. It can be used in admin for map previews. Example usage::
+
+    from django import forms
+    from django.contrib import admin
+    from easy_maps.widgets import AddressWithMapWidget
+    from firms.models import Firm
+
+    class FirmAdmin(admin.ModelAdmin):
+        class form(forms.ModelForm):
+            class Meta:
+                widgets = {
+                    'address': AddressWithMapWidget({'class': 'vTextField'})
+                }
+
+    admin.site.register(Firm, FirmAdmin)
+
+
 Contributing
 ============
 

easy_maps/widgets.py

+from django.forms import TextInput
+from django.template import Template, Context
+
+class AddressWithMapWidget(TextInput):
+    def render(self, name, value, attrs=None):
+        default_html = super(AddressWithMapWidget, self).render(name, value, attrs)
+        map_template = Template("{% load easy_maps_tags %}{% easy_map address 700 200 16 %}")
+        context = Context({'address': value})
+        return default_html + map_template.render(context)