class Location(models.Model): name = models.CharField(max_length=100, verbose_name=u"Локация", default=u'') coords = gis_models.PointField(u"долгота/широта", srid=4326, blank=True, null=True)
class LocationForm(forms.ModelForm): class Meta: model = Location fields = ['name']
class AddLocationPageView(CreateView): model = Location form_class = LocationForm template_name = 'add_location.html'
<form action="" method="POST">{% csrf_token %} <div id="map-add-location" ></div> <div class="col-md-5"> {{ form }} <button type="submit">Add location</button> </div> </form>
$(document).ready(function(){ map = new google.maps.Map($('#map-add-location')[0], mapOptions); map.addListener('click', function(e){ placeMarker(e.latLng, map); var position = marker.getPosition(); }); var marker; function placeMarker(latLng, map) { marker = new google.maps.Marker({ position: latLng, map: map, }); return marker } });
Как сохранить координаты маркера (var position в js) в Location.coords при сохранении формы?
Спасибо!!!