DJANGO: Showing many-to-many fields in template :    # I have this situation :
    **Models:-**
    class Publisher(models.Model):
        name = models.CharField(max_length=30)
        address = models.CharField(max_length=50)
        city = models.CharField(max_length=60)
        state_province = models.CharField(max_length=30)
        country = models.CharField(max_length=50)
        website = models.URLField()
        date = models.DateTimeField()
    
    
        class Meta:
            ordering = ["-name"]
    
        def __unicode__(self):              # __unicode__ on Python 2
            return self.name
    
    class Author(models.Model):
        publisher = models.ForeignKey(Publisher)
        salutation = models.CharField(max_length=10)
        name = models.CharField(max_length=200)
        email = models.EmailField()
        headshot = models.ImageField(upload_to='author_headshots')
    
     	
        def __str__(self):             
            return self.name
    
    
    class Book(models.Model):
        title = models.CharField(max_length=100)
        authors = models.ManyToManyField('Author') 
        publisher = models.ForeignKey(Publisher, on_delete=models.CASCADE)
        publication_date = models.DateField()
    
        def __str__(self):
            return self.title
    
        def get_authors(self):
            return "\n".join([a.name for a in self.authors.all()])

# i want to show authors field in template with Publishers

**Template**:

    {% for a in obj.pk|get_author %}
        {{ a.name }}<br/>
    	{{ a.headshot }}
    {% endfor %}

**Custom Template Tags:**

    def get_author(pk):
    	try:
    		publisher = Publisher.objects.get(pk=pk)
    		print type(publisher)
    		author = Author.objects.filter(Publisher=publisher)
    		print author
    	except:
    		author = []
    	return author
    
    register.filter('get_author', get_author)

    	        