Created
March 18, 2016 23:03
-
-
Save dpineiden/061d25aa5ed3b4f3f289 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.gis.db import models | |
# Create your models here. | |
from django_countries.fields import CountryField | |
#database regiones, provincias y comunas Chile | |
#https://github.com/knxroot/bdcut-cl | |
class Region(models.Model): | |
nombre = models.CharField(max_length=200) | |
numero_decimal = models.CharField(max_length=100, unique = True) | |
numero_romano = models.CharField(max_length=80, blank=True) | |
pais = CountryField(default="CL") | |
@property | |
def nombre_region(self): | |
return self.nombre | |
class Meta: | |
verbose_name='Region' | |
verbose_name_plural = 'Regiones' | |
ordering = ("numero_decimal", ) | |
def __str__(self): | |
return self.nombre | |
def save(self, *args, **kwargs): | |
print(self.pais) | |
roman=['RM','I','II','III','IV','V','VI','VII','VIII','IX','X','XI','XII','XIII','XIV','XV'] | |
print("<"+self.numero_decimal+">") | |
if self.numero_decimal.isdigit(): | |
self.numero_romano = roman[int(self.numero_decimal)] | |
elif self.numero_decimal == "RM": | |
self.numero_romano = roman[0] | |
print(self.numero_romano) | |
super(Region,self).save(*args, **kwargs) | |
class Comuna(models.Model): | |
nombre = models.CharField(max_length = 150, blank=False, unique = True) | |
region = models.ForeignKey('Region') | |
@property | |
def nombre_comuna(self): | |
return self.nombre | |
class Meta: | |
verbose_name='Comuna' | |
verbose_name_plural = 'Comunas' | |
def __str__(self): | |
return self.nombre | |
class Localizacion(models.Model): | |
ubicacion = models.CharField(max_length=200,help_text="calle y nro") | |
comuna = models.ForeignKey(Comuna) | |
geo_point = models.PointField(blank = True) | |
@property | |
def direccion(self): | |
return self.direccion | |
class Meta: | |
verbose_name='Localización' | |
verbose_name_plural = 'Localizaciones' | |
def __str__(self): | |
return self.ubicacion | |
#Definir metodo save para generar el punto geográfico | |
#def save(self): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment