1

I have a model with a gis_models.GeometryField.

class MyModel(django.db.models):
   area = gis_models.GeometryField(null=True, blank=True)

I'm displaying this model on Django admin but i'm using https://github.com/makinacorpus/django-leaflet library.

I already have 100+ rows in the database. when I open the admin page for any of those entries, I'm able to see a polygon being draw. that's perfect! take another case where I have to add a new polygon from the admin page. I am able to draw the map and save the entry. it works as expected. I can see the polygon on the map next time I open that entry on the map.

the problem is when I add a new polygon I don't know what polygons are already there in the DB. so sometimes I add a new polygon that overlaps with existing ones. I was thinking of displaying all the available polygons on the map so that next time I add a new one I won't touch those points on the map. how can we display all the polygons (MultiPolygon) just for the /add/ page?

PS: I couldn't find the method that I can override in Django admin class to render all the polygons. also, I couldn't find the relevant question on StackOverflow or any other source. so please if you think I didn't search enough please point me to the link that you think would be helpful to me for this specific case.

2 Answers 2

0

I think this is not the right way. The best solution is to create your own template for viewing your spatial data. Visit for example https://github.com/makinacorpus/django-leaflet. Another solution is to connect your spatial database to a program such as Quantum GIS, and in this way, you can do CRUD operation with your database.

Sign up to request clarification or add additional context in comments.

Comments

0

1.Use spatial database (I recommend Postgres with PostGIS extension )

https://www.enterprisedb.com/postgres-tutorials/how-use-postgresql-django

DATABASES = {
    'default': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'polygon',
        'USER':'postgres',
        'PASSWORD':'*******',
        'HOST':'localhost',
        'PORT':'5432',
    } }

2.Add django.contrib.gis into your installed apps in settings.py

INSTALLED_APPS = [
    .......
    'django.contrib.gis',
    .....
]
  1. create a model

    #models.py

     from django.contrib.gis.db import models
    
    
     class Polygon(models.Model):
          area=models.MultiPolygonField(srid=4326)
    

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.