added geo module, with region supporting gis data

This commit is contained in:
Sam
2021-01-21 13:18:37 +00:00
parent 944bc7d6c7
commit 9965900791
12 changed files with 5108 additions and 4 deletions

77
geo/models.py Normal file
View File

@@ -0,0 +1,77 @@
from django.contrib.gis.db import models
class Country(models.Model):
"""
Country model
"""
name = models.CharField(max_length = 100)
# internal
created = models.DateTimeField('date of creation', auto_now_add=True)
updated = models.DateTimeField('date last update', auto_now=True)
def __str__(self):
return f'{self.name}'
class Meta:
verbose_name = "País"
verbose_name_plural = "Paises"
class Region(models.Model):
"""
Region model
"""
name = models.CharField(max_length=250)
country = models.ForeignKey(Country,on_delete=models.DO_NOTHING,related_name='regions')
geo = models.MultiPolygonField(null=True)
# internal
created = models.DateTimeField('date of creation', auto_now_add=True)
updated = models.DateTimeField('date last update', auto_now=True)
def __str__(self):
return f'{self.name} [{self.country}]'
class Meta:
verbose_name = "Región"
verbose_name_plural = "Regiones"
class Province(models.Model):
"""
Country model
"""
name = models.CharField(max_length = 100)
region = models.ForeignKey(Region, on_delete=models.DO_NOTHING, related_name='province')
# internal
created = models.DateTimeField('date of creation', auto_now_add=True)
updated = models.DateTimeField('date last update', auto_now=True)
def __str__(self):
return f'{self.name} [{self.region}]'
class Meta:
verbose_name = "Provincia"
verbose_name_plural = "Provincias"
class City(models.Model):
"""
City model
"""
name = models.CharField(max_length = 250)
province = models.ForeignKey(Province, on_delete=models.DO_NOTHING, related_name='city', null=True)
# internal
created = models.DateTimeField('date of creation', auto_now_add=True)
updated = models.DateTimeField('date last update', auto_now=True)
def __str__(self):
return f'{self.name} [{self.province}]'
class Meta:
verbose_name = "Municipio"
verbose_name_plural = "Municipios"