Accessing related models with django-tables2

时光怂恿深爱的人放手 提交于 2019-12-23 12:28:18

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/14461480/accessing-related-models-with-django-tables2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!