python - Django ManyToMany Field with field name values -


manytomany field coming object

model.py

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() 

admin.py

class productsinfoadmin(admin.modeladmin): filter_horizontal = ('category',) admin.site.register(productsinfo, productsinfoadmin) 

so want show name of category field in filter search , want save them objects while doing save.

how customise show name of manytomany field , on save save objects of manytomany field

add __unicode__ method model return string want use.

for python 3, use __str__ instead.

# on productsinfo model def __str__(self):     return self.category.name 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -