我有這個問題,很愚蠢,但好...我有這樣兩種型號:Django的傳遞從兩個模型的數據到模板
class Cliente(models.Model):
CUIT = models.CharField(max_length=50)
Direccion = models.CharField(max_length=100)
Razon_Social = models.CharField(max_length=100)
def __unicode__(self):
return self.Razon_Social
class Factura(models.Model):
TIPO_FACTURA = (
('A', 'A'),
('E', 'E')
)
tipo_Factura = models.CharField(max_length=1, choices= TIPO_FACTURA)
nombre_cliente = models.ForeignKey(Cliente)
fecha_factura = models.DateField()
IRI = models.IntegerField()
numero_De_Factura = models.IntegerField(max_length=50)
descripcion = models.CharField(max_length=140)
importe_Total= models.FloatField()
importe_sin_iva = models.FloatField()
def __unicode__(self):
return "%s - %s" % (unicode(self.nombre_cliente), self.numero_De_Factura)
我爲每個客戶端列出賬單,用戶點擊時它我想顯示有關該法案的一些信息(Factura西班牙語)和大約像其ADRESS客戶的一些信息
這是我的views.py:
def verFactura(request, id_factura):
fact = Factura.objects.get(pk = id_factura)
cliente = Cliente.objects.filter(factura = fact)
template = 'verfacturas.html'
return render_to_response(template, locals())
我試着去獲得Informa公司這個特定法案的客戶端的重刑,所以我可以顯示其信息,但在模板我不能看到任何東西:
<div >
<p>{{fact.tipo_Factura}}</p>
<p>{{fact.nombre_cliente}}</p>
<p>{{cliente.Direccion}}</p>
</div><!-- /.box-body -->
這是我的網址:
URL(R'^ VerFactura /(\ d +)$','apps.Administracion.views.verFactura',name ='verFactura'),
誰能告訴我怎麼做到這一點。顯然,我的代碼有問題,所以我會很感激這個幫助。謝謝你在前進
能否請您正確格式化你的代碼? –
謝謝丹尼爾。對不起,關於那 – user3799942