I have these models:
class Supplier(models.Model):
name = models.CharField(max_length=50)
def __unicode__(self):
return u"%s" % self.name
class SupplierOrder(models.Model):
supplier = models.ForeignKey(Supplier)
numero_invoice = models.CharField(max_length=50)
I have this form:
class SupplierOrderForm(forms.ModelForm):
class Meta:
model = SupplierOrder
In pass a supplier order form to a template in which I have this code:
<table>
{% for f in forms %}
{% for field in f.visible_fields %}
<tr>
<td>{{ field.label_tag }}</td>
<td>{{ field.value }}</td>
</tr>
{% endfor %}
{% endfor %}
The problem is that for supplier it display the supplier id, but I want the supplier name.
This forloop’s
fieldvalue is an instance of BoundField:You can get the value of a BoundField instance as such:
So you could make a trivial template filter:
And use it in your template: