Django ManyToMany Field with field name values
<p><a href="http://i.stack.imgur.com/3KSpq.png" rel="nofollow"><img src="http://i.stack.imgur.com/3KSpq.png" alt="ManyToMany Field Coming as object"></a></p>

<h1>model.py</h1>

<pre><code>class MedtechProductCategory(models.Model):
name = models.CharField(max_length=128, null=False, blank=False)
type = models.CharField(choices=type_choices_for_tag, max_length=512)

class Meta:
    db_table = 'medtech_product_category'

class ProductsInfo(models.Model):
deal_active = models.BooleanField(default=True)
category = models.ManyToManyField(MedtechProductCategory,  related_name='product_info_category')

class Meta:
    db_table = 'products_info'

def getTags(self):
    return self.category.values_list()
</code></pre>

<h1>admin.py</h1>

<pre><code>class ProductsInfoAdmin(admin.ModelAdmin):
filter_horizontal = ('category',)
admin.site.register(ProductsInfo, ProductsInfoAdmin)
</code></pre>

<p>So i want to show the name of the category field in the filter search and want to save them as objects while doing save.</p>

<p>How to customise it to show the name of the manytomany field and on save save the objects of the manytomany field</p>

<p>Add a <code>__unicode__</code> method to your model which will return the string that you want to use.</p>

<p>For python 3, use <code>__str__</code> instead.</p>

<pre><code># on ProductsInfo model
def __str__(self):
    return self.category.name
</code></pre>

python django django-models django-forms django-admin