我已经搜索过这个,但没有太多的运气,所以寻求一些帮助.我正在尝试使用模型中的函数定义向模型定义的表中添加一些额外的列.这是我的代码现在的样子:
# models.py
class MyModel(models.Model):
my_field = models.TextField()
def my_function(self):
# Return some calculated value based on the entry
return my_value
# tables.py
class MyTable(tables.Table):
my_extra_column = tables.Column(....)
class Meta:
model = MyModel
# views.py
table = MyTable(MyModel.objects.all())
RequestConfig(request).configure(table)
return render(request, ....)
Run Code Online (Sandbox Code Playgroud)
我的问题是我可以my_function在传入的条目中访问,MyTable以便我可以my_function在自定义my_extra_column列中显示结果吗?我假设我需要使用访问器,但我无法看到如何使用它来访问查询集数据.谢谢!