【问题标题】:Flask-AppBuilder: How to sort on relationship?Flask-AppBuilder:如何对关系进行排序?
【发布时间】: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]

【问题讨论】:

    标签: python flask-appbuilder


    【解决方案1】:

    改变

    order_columns= ["label","suffix"]
    

    base_order = ("label", "asc")
    

    【讨论】:

      猜你喜欢
      • 2014-12-07
      • 1970-01-01
      • 2020-12-26
      • 2018-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多