I tried to retrieve the polygon which I saved into postgis database. (all polygons) Here is my code:


from django.contrib.gis.db import models

class 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.name


from django.contrib.gis import forms
from .models import MyMap

class MyMapForm(forms.ModelForm):

    class Meta:
        model = MyMap
        fields = ['geom']


from django.shortcuts import render
from django.http import HttpResponse
from .forms import MyMapForm
from .models import MyMap

def 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)


<form action="" method="POST"> 
    <div id="map_canvas"></div> // I use google map api

    {% for details in map_detail %}
    {% endfor %}

I don't know where is my problem which I can not show the polygons in the html file !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.