Commit 08883096 authored by Priit Laes's avatar Priit Laes

Add custom date example for column_type_formatter

parent 45d6d626
...@@ -166,6 +166,7 @@ class BaseModelView(BaseView, ActionsMixin): ...@@ -166,6 +166,7 @@ class BaseModelView(BaseView, ActionsMixin):
Dictionary of value type formatters to be used in the list view. Dictionary of value type formatters to be used in the list view.
By default, two types are formatted: By default, two types are formatted:
1. ``None`` will be displayed as an empty string 1. ``None`` will be displayed as an empty string
2. ``bool`` will be displayed as a checkmark if it is ``True`` 2. ``bool`` will be displayed as a checkmark if it is ``True``
...@@ -176,13 +177,18 @@ class BaseModelView(BaseView, ActionsMixin): ...@@ -176,13 +177,18 @@ class BaseModelView(BaseView, ActionsMixin):
column_type_formatters = dict() column_type_formatters = dict()
If you want to display `NULL` instead of an empty string, you can do If you want to display `NULL` instead of an empty string, you can do
something like this:: something like this. Also comes with bonus `date` formatter::
from datetime import date
from flask_admin.model import typefmt 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 = dict(typefmt.BASE_FORMATTERS)
MY_DEFAULT_FORMATTERS.update({ MY_DEFAULT_FORMATTERS.update({
type(None): typefmt.null_formatter type(None): typefmt.null_formatter,
date: date_format
}) })
class MyModelView(BaseModelView): class MyModelView(BaseModelView):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment