簡體   English   中英

如何允許按外鍵字段排序?

[英]How to allow sorting by foreign key fields?

考慮以下 django-tables2 表:

class ProductMaxIPPortEldCountTable(tables.Table):                             
    vendor = tables.TemplateColumn('{{ record.product.vendor }}')

當我嘗試按vendor對其進行排序時,這是基礎模型中的外鍵,我得到“無法將關鍵字 u'vendor' 解析到字段中。” 錯誤。 如何向 django-tables2 提供有關此列如何鏈接到模型字段的提示?

使用帶有accessorColumn有助於:

class ProductMaxIPPortEldCountTable(tables.Table):                          
    vendor = tables.Column(accessor='product.vendor')           

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM