Help with select_related (),

0

I know I add a foreingKey in TableB and the TabalC I can solve the problem ... quickly but I want to know if there is any way that works and me
paint the price in the html

class TablaA(models.Model):
    nombre = models.CharField(max_length=50)
    # mas campos...

class TablaB(models.Model):
    tabla_a = models.ForeignKey(TablaA)
    precio = models.DecimalField(max_digitals=7,decimal_place=2) 
    # mas campos...

class TablaC(models.Model):
    tabla_a = models.ForeignKey(TablaA)
    cantidad = models.PositiveIntegralField()
    # mas campos...

 ### Esta es mi vista 
 def mat_sal_detall(request, id_sal):
    TablaC = get_object_or_404(TablaC.objects.select_related(), id = id_sal)
    ctx = {'TablaC':TablaC}
    return render(request, 'salida/salida_detalle.html', ctx)

This is my html_list and here I need to put the price

"Do not Price anything as if it did not exist"

<td class="text-center">{{TablaC.TablaA.nombre}}</td> # Funciona
<td class="text-center">{{TablaC.TablaA.TablaB.precio}}</td> # No funciona
    
asked by Tony 04.07.2017 в 05:45
source

1 answer

0

There is no relationship between TableC and TableB. Also, do not enter Table A to get to Table B.

You would have to make a custom label that you pass as a parameter to TableA (as you use TableC.TablaA).

I leave an example in the following URL of custom tag : VIEW EXAMPLE

    
answered by 06.07.2017 / 17:22
source