With django-tables2 how do I display a model @prop

2019-08-07 04:33发布

I have a @property in my model which is basically a string of several values in the model combined.

  @property
    def mfg_link(self):
        return ''.join('http://mfg.com/model/' + str(self.model_numer))

I can add this mfg_link to the list_display on the admin model and it works fine, but its not showing up in the generated table when I pass the queryset to the table, the other fields show up fine.

This seems like something obvious, but unfortunately the couple of hours of searching didn't help.

Thanks a lot!

1条回答
贼婆χ
2楼-- · 2019-08-07 04:38

Do it like this in Table class:

class TableClass(tables.Table):
   mfg_link = tables.Column('mfg_link', order_by='model_numer')

   class Meta:
     model = SomeModel
     sequence = 'model_numer', 'mfg_link'
查看更多
登录 后发表回答