使用django-tables2如何显示模型@property? [英] With django-tables2 how do I display a model @property?

查看:68
本文介绍了使用django-tables2如何显示模型@property?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的模型中有一个 @property ,基本上是模型中多个值的字符串。

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

我可以添加此 mfg_link 到admin模型上的 list_display ,它可以正常工作,但是当我将queryset传递给表时,它没有显示在生成的表中,其他字段显示得很好。

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.

谢谢

推荐答案

在Table类中这样做:

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'

这篇关于使用django-tables2如何显示模型@property?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆