I am able to list the PagosHead items in the template but when I use the " _set.all" in order to get those fields from PagosDetail i've no luck.
Hope you can help me guys!
Models
class PagosHead(models.Model):
numero_pago = models.IntegerField()
numero_socio = models.ForeignKey(Socios, on_delete=models.CASCADE)
fecha_pago = models.DateField(default=datetime.now,null=True,blank=True)
importe_pago_total = models.DecimalField(default=0.00,max_digits=9,decimal_places=2)
observaciones_pago = models.CharField(max_length=100,null=True)
class PagosDetail(models.Model):
pago=models.ForeignKey(PagosHead,on_delete=models.CASCADE)
importe_pago = models.DecimalField(default=0.00,max_digits=9,decimal_places=2)
mes_pago = models.CharField(max_length=10)
ano_pago = models.SmallIntegerField(null=True)
View
#Vista de Cuenta Corriente
@method_decorator(staff_member_required, name='dispatch')
class detalleCC(TemplateView):
template_name = "pagos/cuenta_corriente.html"
contexto={}
print("En detalleCC view")
def get_context_data(self, **kwargs):
contexto = super(detalleCC, self).get_context_data(**kwargs)
contexto={
'pagos': PagosHead.objects.filter(numero_socio_id=self.kwargs['pk']),
}
return contexto
Template
{% for pago in pagos reversed %}
<tr>
<td style="font-size:90%;">{{pago.numero_pago}}</td>
<td style="font-size:90%;">{{pago.fecha_pago}}</td>
<td style="font-size:90%;">{{pago.importe_pago_total}}</td>
<td style="font-size:90%;">{{pago.observaciones_pago}}</td>
<td><a class="btn btn-secondary btn-sm" href="{% url 'pagos:pdf' pk=pago.numero_pago %}" role="button" data-toggle="tooltip" data-placement="top" title="Imprimir"><i class="fa fa-print"></i></a></td>
</tr>
{% for pagosdet in pagos.pagosdetail_set.all %}
<tr>
<td style="font-size:90%;">{{pagosdet.mes_pago}}</td>
</tr>
{% endfor %}
{% endfor %}
</tbody>
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4ef2d447-48aa-4f44-9695-e72db04ecd70n%40googlegroups.com.
No comments:
Post a Comment