Dudes, I received online help.

In the template there was a mistype error:

{% for pagosdet in pagos.pagosdetail_set.all %}  => *
{% for pagosdet in pago.pagosdetail_set.all %}   ( Without 's')*

Thanks for reading,



El vie, 23 abr 2021 a las 17:37, Walter Randazzo (<wwranda...@gmail.com>)
escribió:

> Hi there,  I am trying to list in a template a bunch of fields  of the
> model (PagosDetail) that is related to another one (PagosHead) via
> numero_pago field.
>
> 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+unsubscr...@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
> <https://groups.google.com/d/msgid/django-users/4ef2d447-48aa-4f44-9695-e72db04ecd70n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAL7Dry4WYY9x0X-bSKRtO6CDUkk2k%3DtWZTioF5UZVG8mOQ9G4w%40mail.gmail.com.

Reply via email to