I tried to retrieve the polygon which I saved into postgis database. (all polygons)Here is my code:
models.py
from django.contrib.gis.db import modelsclass MyMap(models.Model): name = models.CharField(max_length=50, blank=True, null=True) timestamp = models.DateTimeField(auto_now_add=True, auto_now=False) geom = models.GeometryCollectionField(srid=4326, null=True) objects = models.GeoManager() def __unicode__(self): return self.nameforms.py
from django.contrib.gis import formsfrom .models import MyMapclass MyMapForm(forms.ModelForm): class Meta: model = MyMap fields = ['geom']views.py
from django.shortcuts import renderfrom django.http import HttpResponsefrom .forms import MyMapFormfrom .models import MyMapdef map(request): map_info = MyMap.objects.all() map_data = { "map_detail": map_info } return render(request, 'mymap.html', map_data)def ajax(request): if request.POST.has_key('geom'): form = MyMapForm(request.POST or None) ...mymap.html
{%csrf_token%}
// I use google map api {% for details in map_detail %} {{detail.geom}} {% endfor %}
I don't know where is my problem which I can not show the polygons in the html file !
أكثر...
models.py
from django.contrib.gis.db import modelsclass MyMap(models.Model): name = models.CharField(max_length=50, blank=True, null=True) timestamp = models.DateTimeField(auto_now_add=True, auto_now=False) geom = models.GeometryCollectionField(srid=4326, null=True) objects = models.GeoManager() def __unicode__(self): return self.nameforms.py
from django.contrib.gis import formsfrom .models import MyMapclass MyMapForm(forms.ModelForm): class Meta: model = MyMap fields = ['geom']views.py
from django.shortcuts import renderfrom django.http import HttpResponsefrom .forms import MyMapFormfrom .models import MyMapdef map(request): map_info = MyMap.objects.all() map_data = { "map_detail": map_info } return render(request, 'mymap.html', map_data)def ajax(request): if request.POST.has_key('geom'): form = MyMapForm(request.POST or None) ...mymap.html
{%csrf_token%}
// I use google map api {% for details in map_detail %} {{detail.geom}} {% endfor %}
I don't know where is my problem which I can not show the polygons in the html file !
أكثر...