django - Get all ManyToManyField-Entries of an object in models.py -


i want have tag list in admin panel of simple blog app. manytomanyfields aren't allowed input list_display want create method getting tags , put method in list.

my problem don't know how can access in model other class.

my models.py

class tag(models.model):     tag = models.charfield(max_length=25)      def __unicode__(self):         return self.tag   class post(models.model):     author = models.foreignkey(user)      publication = models.datetimefield()      title = models.charfield(max_length=100)     summary = models.textfield(max_length=150)     content = models.textfield(max_length=9999)      tag = models.manytomanyfield(tag)      commentsallowed = models.booleanfield()      def gettags(self):         return post.tag.all()    <-----------------------------------      def __unicode__(self):         return self.title 

my admin.py

class postadmin(admin.modeladmin):     date_hierarchy = 'publication'     list_display = ('author', 'title', 'publication', 'gettags') 

this returns me <django.db.models.fields.related.reversemanyrelatedobjectsdescriptor object @ 0xb8e24fcc>, want tag names.

you want self.tags.all(), instance has relationship, not class.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -