Skip to content

Instantly share code, notes, and snippets.

@mgaitan
Created November 9, 2013 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgaitan/7385647 to your computer and use it in GitHub Desktop.
Save mgaitan/7385647 to your computer and use it in GitHub Desktop.
from django.db import models
from django.db.models import Sum
class Municipio(models.Model):
nombre = models.CharField(max_length=100)
def __unicode__(self):
return self.nombre
class Circuito(models.Model):
numero = models.CharField(max_length=100)
municipio = models.ForeignKey('Municipio', null=True)
def __unicode__(self):
return u"Circuito %s (%s)" % (self.numero, self.municipio)
class Mesa(models.Model):
circuito = models.ForeignKey('Circuito', null=True)
numero = models.CharField(max_length=100, unique=True)
url = models.URLField()
@property
def computados(self):
return self.votomesa_set.aggregate(Sum('votos'))['votos__sum']
def __unicode__(self):
return u"Mesa %s (%s)" % (self.numero, self.circuito)
class Opcion(models.Model):
# partido, blanco, etc.
nombre = models.CharField(max_length=100, unique=True)
def __unicode__(self):
return self.nombre
class VotoMesa(models.Model):
mesa = models.ForeignKey('Mesa')
opcion = models.ForeignKey('Opcion')
votos = models.IntegerField()
def __unicode__(self):
return u"%s: %d" % (self.opcion, self.votos)
class Meta:
unique_together = ('mesa', 'opcion')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment