django - Display object from different table -


i using django , django-tables2. have model looks this:

# models.py class word(models.model): [...]     word_category = models.foreignkey('wordcategory', db_column='word_category')     class meta:         managed = false         db_table = 'word'  class wordcategory(models.model):     [...]     name = models.charfield(max_length=255)     class meta:         managed = false         db_table = 'wordcategory' 

in table, displaying entries table word, every word object want show name value of corresponding wordcategory object. how do that?

edit: table class looks this, no category being printed, neither in console or on website:

class categorycolumn(tables.column):     def render(self, value):         return value.name   class wordstable(tables.table):     category = categorycolumn(verbose_name="kategorie", accessor="category")      def render_category(self, value):         print value.name         return value.name      class meta:         model = word         attrs = {"class": "table"} 

in django-tables2, can add render method customize how column rendered.

class wordtable(tables.table):     def render_word_category(self, value):         """display name of category"""         return value.name      class meta:         model = word 

an alternative change __str__ method (__unicode__ in python 2) return name. affect other places display word categories, might not want make change.

class wordcategory(models.model):     [...]     name = models.charfield(max_length=255)      def __str__(self):         return self.name 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -