El martes, 11 de diciembre de 2018, 9:46:07 (UTC-5), Yarving Liu escribió: > > Can you show us the code? > Hello and thanks for your response:
{{ ccosto.gastos_mes }} and {{ ccosto.gastos_ano }} yield None Nevertheless if I print the response content when calling that URI with django test client it shows the expected values. ## models.py from django.db import models from django.db.models import Q, Sum from datetime import datetime # Create your models here. class CentroCosto(models.Model): ocostcodigo = models.IntegerField(db_column='OCostCodigo', primary_key=True) # Field name made lowercase. ocostdescrip = models.TextField(db_column='OCostDescrip', blank=True) # Field name made lowercase. @property def codigo(self): return self.ocostcodigo def listar_gastos(self): return self.gastos_set(manager='gastado').all() def gastos_mes(self, mes=datetime.today().month): _gastos = self.listar_gastos().filter(smaycosfechamodif__month=mes).aggregate(Sum('smaycospartidaimporte')) return _gastos['smaycospartidaimporte__sum'] def gastos_ano(self, ano=datetime.today().year): _gastos = self.listar_gastos().filter(smaycosfechamodif__year=ano).aggregate(Sum('smaycospartidaimporte')) return _gastos['smaycospartidaimporte__sum'] class GastosManager(models.Manager): def get_queryset(self): return super().get_queryset().filter(Q(smaycoscuenta=702) | Q(smaycoscuenta=703) | Q(smaycoscuenta=731) | Q(smaycoscuenta=822)) class Gastos(models.Model): smaycosid = models.DecimalField(db_column='SMayCosId', max_digits=18, decimal_places=0, primary_key=True) smaycoscuenta = models.SmallIntegerField(db_column='SmayCosCuenta', blank=True, null=True) smaycospartidaimporte = models.DecimalField(db_column='SMayCosPartidaImporte', max_digits=19, decimal_places=4, blank=True, null=True) smaycossubelem = models.IntegerField(db_column='SMayCosSubelem', blank=True, null=True) smaycosocostocodigo = models.ForeignKey(CentroCosto, on_delete=models.CASCADE) smaycosfechamodif = models.DateTimeField(db_column='SMayCosFechaModif', blank=True, null=True) objects = models.Manager() gastado = GastosManager() @property def codigo(self): return self.smaycosocostocodigo @property def importe(self): return self.smaycospartidaimporte ## views.py from django.views import generic from .models import Gastos from .models import CentroCosto # Create your views here. class CentrosDeCostoListView(generic.ListView): template_name = 'gastos/centrosdecosto.html' context_object_name = 'centroscosto' model = CentroCosto ## centrosdecosto.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Resumen Centros de Costo</title> </head> <body> <table> <thead> <tr> <th>Centro de Costo</th> <th>Mes Actual</th> <th>Acumulado</th> </tr> </thead> {% for ccosto in centroscosto %} <tr> <td>{{ ccosto.codigo }}</td><td>{{ ccosto.gastos_mes }}</td><td>{{ ccosto.gastos_ano }}</td> </tr> {% endfor %} </table> </body> </html> -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f0be579c-daa0-45e9-b050-f2c117cc66c4%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.