flask-admin,自定義視圖參數設置。


# 許可類
    can_create = True
    """是否可以新建"""

    can_edit = True
    """是否可以編輯"""

    can_delete = True
    """是否可以編輯"""

    can_view_details = False
    """是否顯示詳情,如果你設置了不顯示,可以設置是否使用詳情顯示未顯示的內容。 """

    can_export = False
    """是否可以導出"""

    # jinjia2模板
    list_template = 'admin/model/list.html'
    """列表模板的路徑"""

    edit_template = 'admin/model/edit.html'
    """編輯的模板路徑"""

    create_template = 'admin/model/create.html'
    """新建的模板路徑"""

    details_template = 'admin/model/details.html'
    """詳情的模板路徑"""

    # 動態模板
    edit_modal_template = 'admin/model/modals/edit.html'
    """動態編輯模板"""

    create_modal_template = 'admin/model/modals/create.html'
    """動態創建模板"""

    details_modal_template = 'admin/model/modals/details.html'
    """動態詳情模板"""

    # 動態模式設置
    edit_modal = False
    """是否使用動態編輯"""

    create_modal = False
    """是否使用動態創建"""

    details_modal = False
    """是否使用動態詳情"""

    # 自定義設置
    column_list = ObsoleteAttr('column_list', 'list_columns', None)
    """自定義在列表顯示的字段"""
    """
        例:
            column_list = ('name', 'last_name', 'email')
            column_list = ('name', User.last_name)

        如果使用sqlalchemy定義了relationship,那么可以這樣設置:
            column_list = ('<relationship>.<related column name>',)
    """

    column_exclude_list = ObsoleteAttr('column_exclude_list',
                                       'excluded_list_columns', None)
    """ 在列表排除的字段名,用法和上條一樣 """

    column_details_list = None
    """ 詳情視圖顯示的字段名集合,如果不設置,默認值是None,顯示所有的字段名 """

    column_details_exclude_list = None
    """ 詳情視圖隱藏的字段名集合,如果不設置,顯示所有的字段名 """

    column_export_list = None
    """ 設置導出的字段名列表,如果不設置,導出所有的字段名 """

    column_export_exclude_list = None
    """ 設置導出時排除的字段名,如果不設置,導出所有的字段名  """

    column_formatters = ObsoleteAttr('column_formatters', 'list_formatters', dict())
    """ 顯示視圖的格式化顯示,沒看懂啊"""
    """
        For example, if you want to show price multiplied by
        two, you can do something like this::

            class MyModelView(BaseModelView):
                column_formatters = dict(price=lambda v, c, m, p: m.price*2)

        or using Jinja2 `macro` in template::

            from flask_admin.model.template import macro

            class MyModelView(BaseModelView):
                column_formatters = dict(price=macro('render_price'))

            # in template
            {% macro render_price(model, column) %}
                {{ model.price * 2 }}
            {% endmacro %}

        The Callback function has the prototype::

            def formatter(view, context, model, name):
                # `view` is current administrative view
                # `context` is instance of jinja2.runtime.Context
                # `model` is model instance
                # `name` is property name
                pass
    """

    column_formatters_export = None
    """同樣沒看懂"""
    """
        Dictionary of list view column formatters to be used for export.

        Defaults to column_formatters when set to None.

        Functions the same way as column_formatters except
        that macros are not supported.
    """

    column_formatters_detail = None
    """同樣沒看懂"""
    """
        Dictionary of list view column formatters to be used for the detail view.

        Defaults to column_formatters when set to None.

        Functions the same way as column_formatters except
        that macros are not supported.
    """

    column_type_formatters = ObsoleteAttr('column_type_formatters', 'list_type_formatters', None)
    """要在列表視圖中使用的值類型格式化程序字典。"""
    """
        Dictionary of value type formatters to be used in the list view.

        By default, three types are formatted:

        1. ``None`` will be displayed as an empty string
        2. ``bool`` will be displayed as a checkmark if it is ``True``
        3. ``list`` will be joined using ', '

        If you don't like the default behavior and don't want any type formatters
        applied, just override this property with an empty dictionary::

            class MyModelView(BaseModelView):
                column_type_formatters = dict()

        If you want to display `NULL` instead of an empty string, you can do
        something like this. Also comes with bonus `date` formatter::

            from datetime import date
            from flask_admin.model import typefmt

            def date_format(view, value):
                return value.strftime('%d.%m.%Y')

            MY_DEFAULT_FORMATTERS = dict(typefmt.BASE_FORMATTERS)
            MY_DEFAULT_FORMATTERS.update({
                    type(None): typefmt.null_formatter,
                    date: date_format
                })

            class MyModelView(BaseModelView):
                column_type_formatters = MY_DEFAULT_FORMATTERS

        Type formatters have lower priority than list column formatters.

        The callback function has following prototype::

            def type_formatter(view, value):
                # `view` is current administrative view
                # `value` value to format
                pass
    """

    column_type_formatters_export = None
    """要在導出中使用的值類型格式化程序的字典。 """
    """
        Dictionary of value type formatters to be used in the export.

        By default, two types are formatted:

        1. ``None`` will be displayed as an empty string
        2. ``list`` will be joined using ', '

        Functions the same way as column_type_formatters.
    """

    column_type_formatters_detail = None
    """要在詳細信息視圖中使用的值類型格式化程序字典。 """
    """
        Dictionary of value type formatters to be used in the detail view.

        By default, two types are formatted:

        1. ``None`` will be displayed as an empty string
        2. ``list`` will be joined using ', '

        Functions the same way as column_type_formatters.
    """

    column_labels = ObsoleteAttr('column_labels', 'rename_columns', None)
    """自定義列名的顯示:"""
    """
        例:
        class MyModelView(BaseModelView):
            column_labels = dict(name='Name', last_name='Last Name')
        例2:  可以把custom_field放在別的文件,統一更改
        custom_field={
            'name':'姓名',
            'last_name':'姓氏'
        }
        column_labels = custom_field
    """

    column_descriptions = None
    """字典,其中鍵是列名,值是“列表視圖”列或添加/編輯表單字段的說明。 """
    """
         沒明白

        For example::

            class MyModelView(BaseModelView):
                column_descriptions = dict(
                    full_name='First and Last name'
                )
    """

    column_sortable_list = ObsoleteAttr('column_sortable_list',
                                        'sortable_columns',
                                        None)
    """列表視圖的可排序列的集合。如果設置為“None”,將從模型中獲取它們。 """
    """
        例:
            class MyModelView(BaseModelView):
                column_sortable_list = ('name', 'last_name')

        如果要顯式指定排序時要使用的字段/列,可以使用元組:
            class MyModelView(BaseModelView):
                column_sortable_list = ('name', ('user', 'user.username'))

        還可以指定排序時要使用的多個字段: :
            class MyModelView(BaseModelView):
                column_sortable_list = (
                    'name', ('user', ('user.first_name', 'user.last_name')))

        使用SQLAlchemy模型時,可以使用模型屬性而不是字符串: :
            class MyModelView(BaseModelView):
                column_sortable_list = ('name', ('user', User.username))
    """

    column_default_sort = None
    """默認排序列。"""
    """
        Default sort column if no sorting is applied.

        Example::

            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)]
    """

    column_searchable_list = ObsoleteAttr('column_searchable_list',
                                          'searchable_columns',
                                          None)
    """可搜索列的集合"""
    """
        A collection of the searchable columns. It is assumed that only
        text-only fields are searchable, but it is up to the model
        implementation to decide.

        Example::

            class MyModelView(BaseModelView):
                column_searchable_list = ('name', 'email')
    """

    column_editable_list = None
    """ 可從列表視圖編輯的列的集合。 """
    """
        Collection of the columns which can be edited from the list view.

        For example::

            class MyModelView(BaseModelView):
                column_editable_list = ('name', 'last_name')
    """

    column_choices = None
    """ 將選項映射到列表視圖中的列 """
    """
        Map choices to columns in list view

        Example::

            class MyModelView(BaseModelView):
                column_choices = {
                    'my_column': [
                        ('db_value', 'display_value'),
                    ]
                }
    """

    column_filters =
    """列篩選器的集合"""
    """
        Collection of the column filters.

        Can contain either field names or instances of :class:`~flask_admin.model.filters.BaseFilter` classes.

        Example::

            class MyModelView(BaseModelView):
                column_filters = ('user', 'email')
    """

    named_filter_urls = False
    """ 設置為True可在URL參數中對篩選器使用人類可讀的名稱。 """
    """
        Set to True to use human-readable names for filters in URL parameters.

        False by default so as to be robust across translations.

        Changing this parameter will break any existing URLs that have filters.
    """

    column_display_pk = ObsoleteAttr('column_display_pk',
                                     'list_display_pk',
                                     False)
    """控制是否應在列表視圖中顯示主鍵"""
    """
        Controls if the primary key should be displayed in the list view.
    """

    column_display_actions = True
    """控制行操作(編輯、刪除、詳細信息等)的顯示"""
    """
        Controls the display of the row actions (edit, delete, details, etc.)
        column in the list view.

        Useful for preventing a blank column from displaying if your view does
        not use any build-in or custom row actions.

        This column is not hidden automatically due to backwards compatibility.

        Note: This only affects display and does not control whether the row
        actions endpoints are accessible.
    """

    column_extra_row_actions = None
    """行操作列表"""
    """
        List of row actions (instances of :class:`~flask_admin.model.template.BaseListRowAction`).

        Flask-Admin will generate standard per-row actions (edit, delete, etc)
        and will append custom actions from this list right after them.

        For example::

            from flask_admin.model.template import EndpointLinkRowAction, LinkRowAction

            class MyModelView(BaseModelView):
                column_extra_row_actions = [
                    LinkRowAction('glyphicon glyphicon-off', 'http://direct.link/?id={row_id}'),
                    EndpointLinkRowAction('glyphicon glyphicon-test', 'my_view.index_view')
                ]
    """

    simple_list_pager = False
    """啟用或禁用簡單列表。"""

    """如果啟用,模型接口將不運行計數查詢,只顯示上一頁/下一頁按鈕。 """
    """
        Enable or disable simple list pager.
        If enabled, model interface would not run count query and will only show prev/next pager buttons.
    """

    form = None
    """表單類。如果要對模型使用自定義窗體,則重寫。"""
    """
        Form class. Override if you want to use custom form for your model.
        Will completely disable form scaffolding functionality.
    
        For example::
    
            class MyForm(Form):
                name = StringField('Name')
    
            class MyModelView(BaseModelView):
                form = MyForm
    """

    form_base_class = BaseForm
    """基本窗體類。將在創建模型窗體時由窗體腳手架函數使用。 """
    """
        Base form class. Will be used by form scaffolding function when creating model form.
    
        Useful if you want to have custom constructor or override some fields.
    
        Example::
    
            class MyBaseForm(Form):
                def do_something(self):
                    pass
    
            class MyModelView(BaseModelView):
                form_base_class = MyBaseForm
    
    """

    form_args = None
    """表單域參數字典。請參閱WTForms文檔以了解可能的選項列表。 """
    """
        Dictionary of form field arguments. Refer to WTForms documentation for
        list of possible options.
    
        Example::
    
            from wtforms.validators import DataRequired
            class MyModelView(BaseModelView):
                form_args = dict(
                    name=dict(label='First Name', validators=[DataRequired()])
                )
    """

    form_columns = None
    """窗體的模型字段名的集合"""
    """
        Collection of the model field names for the form. If set to `None` will
        get them from the model.
    
        Example::
    
            class MyModelView(BaseModelView):
                form_columns = ('name', 'email')
    
        (Added in 1.4.0) SQLAlchemy model attributes can be used instead of
        strings::
    
            class MyModelView(BaseModelView):
                form_columns = ('name', User.last_name)
    
        SQLA Note: Model attributes must be on the same model as your ModelView
        or you will need to use `inline_models`.
    """

    form_excluded_columns = ObsoleteAttr('form_excluded_columns',
                                         'excluded_form_columns',
                                         None)
    """排除的表單字段名的集合"""
    """
        Collection of excluded form field names.
    
        For example::
    
            class MyModelView(BaseModelView):
                form_excluded_columns = ('last_name', 'email')
    """

    form_overrides = None
    """表單列重寫字典"""
    """
        Dictionary of form column overrides.
    
        Example::
    
            class MyModelView(BaseModelView):
                form_overrides = dict(name=wtf.FileField)
    """

    form_widget_args = None
    """表單部件參數"""
    """
        Dictionary of form widget rendering arguments.
        Use this to customize how widget is rendered without using custom template.
    
        Example::
    
            class MyModelView(BaseModelView):
                form_widget_args = {
                    'description': {
                        'rows': 10,
                        'style': 'color: black'
                    },
                    'other_field': {
                        'disabled': True
                    }
                }
    
        Changing the format of a DateTimeField will require changes to both form_widget_args and form_args.
    
        Example::
    
            form_args = dict(
                start=dict(format='%Y-%m-%d %I:%M %p') # changes how the input is parsed by strptime (12 hour time)
            )
            form_widget_args = dict(
                start={
                    'data-date-format': u'yyyy-mm-dd HH:ii P',
                    'data-show-meridian': 'True'
                } # changes how the DateTimeField displays the time
            )
    """

    form_extra_fields = None
    """附加字段字典"""
    """
        Dictionary of additional fields.
    
        Example::
    
            class MyModelView(BaseModelView):
                form_extra_fields = {
                    'password': PasswordField('Password')
                }
    
        You can control order of form fields using ``form_columns`` property. For example::
    
            class MyModelView(BaseModelView):
                form_columns = ('name', 'email', 'password', 'secret')
    
                form_extra_fields = {
                    'password': PasswordField('Password')
                }
    
        In this case, password field will be put between email and secret fields that are autogenerated.
    """

    form_ajax_refs = None
    """使用AJAX加載外鍵模型。"""
    """
        Use AJAX for foreign key model loading.
    
        Should contain dictionary, where key is field name and value is either a dictionary which
        configures AJAX lookups or backend-specific `AjaxModelLoader` class instance.
    
        For example, it can look like::
    
            class MyModelView(BaseModelView):
                form_ajax_refs = {
                    'user': {
                        'fields': ('first_name', 'last_name', 'email'),
                        'placeholder': 'Please select',
                        'page_size': 10,
                        'minimum_input_length': 0,
                    }
                }
    
        Or with SQLAlchemy backend like this::
    
            class MyModelView(BaseModelView):
                form_ajax_refs = {
                    'user': QueryAjaxModelLoader('user', db.session, User, fields=['email'], page_size=10)
                }
    
        If you need custom loading functionality, you can implement your custom loading behavior
        in your `AjaxModelLoader` class.
    """

    form_rules = None
    """ 模型創建窗體的呈現規則列表。 """
    """
        List of rendering rules for model creation form.
    
        This property changed default form rendering behavior and makes possible to rearrange order
        of rendered fields, add some text between fields, group them, etc. If not set, will use
        default Flask-Admin form rendering logic.
    
        Here's simple example which illustrates how to use::
    
            from flask_admin.form import rules
    
            class MyModelView(ModelView):
                form_rules = [
                    # Define field set with header text and four fields
                    rules.FieldSet(('first_name', 'last_name', 'email', 'phone'), 'User'),
                    # ... and it is just shortcut for:
                    rules.Header('User'),
                    rules.Field('first_name'),
                    rules.Field('last_name'),
                    # ...
                    # It is possible to create custom rule blocks:
                    MyBlock('Hello World'),
                    # It is possible to call macros from current context
                    rules.Macro('my_macro', foobar='baz')
                ]
    """

    form_edit_rules = None
    """編輯表單的自定義規則。如果存在,則重寫“表單規則”。 """
    """
        Customized rules for the edit form. Override `form_rules` if present.
    """

    form_create_rules = None
    """"創建表單的自定義規則。如果存在,則重寫“表單規則”。 """
    """
        Customized rules for the create form. Override `form_rules` if present.
    """

    # Actions
    action_disallowed_list = ObsoleteAttr('action_disallowed_list',
                                          'disallowed_actions',
                                          [])
    """ 一組不允許的操作名。 """
    """
        Set of disallowed action names. For example, if you want to disable
        mass model deletion, do something like this:
    
            class MyModelView(BaseModelView):
                action_disallowed_list = ['delete']
    """

    # Export settings
    export_max_rows = 0
    """允許導出的最大行數。 """
    """
        Maximum number of rows allowed for export.
    
        Unlimited by default. Uses `page_size` if set to `None`.
    """

    export_types = ['csv']
    """  可用導出文件類型的列表 """
    """
    data.export('csv')
    data.export('json')
    data.export('yaml')
    data.export('xls')
    data.export('df')
    data.export('xlsx')????
    """
    """
        A list of available export filetypes. `csv` only is default, but any
        filetypes supported by tablib can be used.
    
        Check tablib for https://github.com/kennethreitz/tablib/blob/master/README.rst
        for supported types.
    """

    # Pagination settings
    page_size = 20
    """默認分頁大小"""
    """
        Default page size for pagination.
    """

    can_set_page_size = False
    """是否可以設置分頁大小,可選20,50,100"""
    """
        Allows to select page size via dropdown list
    """


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM