【发布时间】:2021-01-07 08:38:46
【问题描述】:
根据documentation,使用order_columns可以指定哪些列允许排序,在表头添加蓝色箭头选择升序或降序排序。
但是,我还想通过名为“softwareproduct”的关系对另一个表进行排序,但是当我将其添加到 order_columns 时,它会崩溃(因为它不是真正的列,而是关系)。该文档还列出了 order_rel_fields,我也尝试过,但没有向“softwareproduct”“列”/关系添加排序功能:
Add_columns、edit_columns、show_columns 和 list_columns 工作得非常好,只有 order 不能,尽管“softwareproduct”在技术上不是一个真正的列而是一个关系。
我怎样才能让用户对这种关系进行排序?
models.py
>[...]
class Softwareproduct(Model):
suffix = Column(String(200), primary_key=True)
label = Column(String(200), nullable=False)
[...]
def __repr__(self):
return self.label
class Citation(Model):
suffix = Column(String(200), primary_key=True)
swp_suffix = Column(String(200), ForeignKey("softwareproduct.suffix"),nullable=False)
softwareproduct = relationship("Softwareproduct")
label = Column(String(200), nullable=False)
def __repr__(self):
return self.label
views.py
>class CitationView(ModelView):
datamodel = SQLAInterface(Citation)
label_columns = {'label':'Citation', 'suffix': 'ID'}
add_columns = ['softwareproduct', "label", "suffix", "classified"]
edit_columns = ['softwareproduct', "label", "suffix","classified"]
show_columns = ['softwareproduct', "label", "suffix","classified"]
list_columns = ['softwareproduct', "label", "suffix","classified"]
order_columns= ["label","suffix"]
order_rel_fields = {'softwareproduct': ('label', 'asc')}
related_views = [ClassifiedView]
【问题讨论】: