使用django-tables2访问相关模型 [英] Accessing related models with django-tables2

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

问题描述

任何人都可以提供一个清楚的例子,说明如何使用django-tables2创建一个表对象,该对象从多个相关模型(即关系连接)中选择和呈现数据。文档意味着这是可能的,但不说如何。



在正常的django中, select_related()功能很好,但我无法解决如何在django-tables2中实现这一点。我注意到有类似主题的其他未回答的问题

解决方案

首先, select_related()不需要访问相关数据,它是出于性能原因。对于django-tables2,您需要定义一个访问器。例如: https://github.com/bradleyayers/django-tables2/issues/ 106


Can anyone provide a clear example of how to create a table object using django-tables2 that selects and presents data from multiple related models (ie a relational join)? The documentation implies this is possible, but does not say how.

In normal django the select_related() function works nicely, but I cannot work out how to implement this in django-tables2. I note there are other unanswered questions on similar topics.

解决方案

First, select_related() is not required to access related data, it is there for performance reasons. For django-tables2, you need to define an accessor. An example is here: https://github.com/bradleyayers/django-tables2/issues/106

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

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