models.py
class Fish(models.Model):
sci_name = models.CharField(max_length=50)
com_name = models.CharField(max_length=50)
...
class Info(models.Model):
fish = models.ManyToManyField(Fish)
short_description = models.TextField(max_length=200)
...
views.py
def available(request):
in_stock = Info.objects.order_by('id')
...
context = RequestContext(request, {
'in_stock': in_stock,
...
available.html
{% for fishnumber in in_stock %}
{{ fishnumber.short_description }} //this line works
{{ fishnumber.fish.sci_name }} //this line doesn't work
{% for fish in fishnumber.fish.all %} //this loop works
{{ fish.sci_name }}
{% endfor %}
I want to access the sci_name field through the many to many relationship Info has with Fish, without that second for loop. I have searched the documentation and google, but all the answers I can find show how to access the field using a loop through fishnumber.fish.all. This works fine, but I want to specify the exact row in the Fish table and select the element from the sci_name column, without looping through all the rows in the many to many relationship between Info and Fish.