1
我是新來的瓶子管理員,我需要將刪除按鈕移動到編輯視圖。瓶頸管理 - 移動刪除按鈕來編輯視圖
這裏是我的其他視圖繼承的AdminModelView類。
class AdminModelView(sqla.ModelView):
can_view_details = True
# column_extra_row_actions = [ViewRowAction()]
def is_accessible(self):
if not current_user.is_active or not current_user.is_authenticated:
return False
if current_user.can('administrator'):
return True
return False
def _handle_view(self, name, **kwargs):
"""
Override builtin _handle_view in order to redirect users when a view is not accessible.
"""
if not self.is_accessible():
if current_user.is_authenticated:
# permission denied
abort(403)
else:
# login
return redirect(url_for('auth.login', next=request.url))
print(self._edit_form_class)
def get_list_row_actions(self):
"""
Return list of row action objects, each is instance of
:class:`~flask_admin.model.template.BaseListRowAction`
"""
actions = []
if self.can_view_details:
if self.details_modal:
actions.append(template.ViewPopupRowAction())
else:
actions.append(template.ViewRowAction())
return actions + (self.column_extra_row_actions or [])
我重新定義了get_list_row_actions
,使編輯和刪除按鈕從列表視圖中消失。我想知道是否有我可以更改的AdminModelView
類的一部分,或者是否需要更改編輯表單的模板。
也想解決這個問題。你找到答案了嗎? – Sparrowcide
我們必須編寫'/ delete'端點並將該按鈕添加到模板。現在發佈答案。 –