def selected_tags(self):これを
'''return selected tags'''
tag_titles = []
for tag_obj in self.tags.all():
tag_titles.append(tag_obj.title)
return tag_titles
list_display = ('title', 'url', 'selected_tags')みたいにして読ませる。
def selected_domain(self):こんな感じ。これでManyToManyFieldも安心やぁ~(´∀`)
""" ManyToManyFieldを返す """
domain_titles = []
for cnt in range(len(self.domain.all())):
if cnt < 2:
domain_titles.append(self.domain.all()[cnt].domain)
domain_titles= str(domain_titles) + ' ...'
return self.cooked_MtMList(domain_titles)
def cooked_MtMList(self, str):
import re
p = re.compile( "\[|\]|u'|'")
str = p.sub('',str)
return str
http://kapi.jp/kapi_blog/88
2007年11月25日
関連カテゴリ django