我有一个a
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Anthony.JACCARD\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py",rgs)
ge()
problem
te str (not "int") to str
设置为column_default_sort
,例如custom_id
的格式,我只想对10/K/2019
部分进行排序,以便字母不会破坏数字排序,如何在flask-admin中进行设置?
我目前的10/
答案 0 :(得分:0)
通过阅读BaseModelView
的源代码,很明显,尚不支持所需的过滤类型。
请参阅以下代码:
column_default_sort = None
# Default sort column if no sorting is applied.
# Examples:
class MyModelView(BaseModelView):
column_default_sort = 'user'
You can use tuple to control ascending descending order. In following example, items will be sorted in descending order:
class MyModelView(BaseModelView):
column_default_sort = ('user', True)
If you want to sort by more than one column, you can pass a list of tuples:
class MyModelView(BaseModelView):
column_default_sort = [('name', True), ('last_name', True)]
# Source code reference
def _get_default_order(self):
"""
Return default sort order
"""
if self.column_default_sort:
if isinstance(self.column_default_sort, list):
return self.column_default_sort
if isinstance(self.column_default_sort, tuple):
return [self.column_default_sort]
else:
return [(self.column_default_sort, False)]
return None
您必须找到一种方法来规避BaseModelView
之外的过滤。
答案 1 :(得分:0)
您可以使用sort key为列提供column_sortable_list
,如下所示:
from sqlalchemy.ext.hybrid import hybrid_property
class MyModel(db.Model):
@hybrid_property
def formatted_custom_id(self):
return self.custom_id[0:2] # Whatever your format is
class MyView(BaseModelView):
column_sortable_list = (('custom_id', (MyModel.formatted_custom_id,)),)
column_default_sort = (MyModel.formatted_custom_id, False)
与文档相反,排序键必须在一个元组中,即使它只是一列。这就是(MyModel.formatted_custom_id,)
部分。