Skip to content

Commit

Permalink
[api] [docs] New, Enum fields support
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgaspar committed Apr 1, 2019
1 parent 91d2823 commit 4a7f643
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
23 changes: 23 additions & 0 deletions docs/rest_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1152,3 +1152,26 @@ a simpler way of doing this using ``validators_columns`` property::
validators_columns = {'name': validate_name}


Enum Fields
-----------

``ModelRestApi`` offers support for **Enum** fields, you have to declare them
on a specific way::

class GenderEnum(enum.Enum):
male = 'Male'
female = 'Female'


class Contact(Model):
id = Column(Integer, primary_key=True)
name = Column(String(150), unique=True, nullable=False)
address = Column(String(564))
birthday = Column(Date, nullable=True)
personal_phone = Column(String(20))
personal_celphone = Column(String(20))
contact_group_id = Column(Integer, ForeignKey('contact_group.id'), nullable=False)
contact_group = relationship("ContactGroup")
gender = Column(Enum(GenderEnum), nullable=False, info={"enum_class": GenderEnum})

Notice the ``info={"enum_class": GenderEnum}``
12 changes: 0 additions & 12 deletions examples/quickhowto/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,6 @@ class ContactTimeChartView(GroupByChartView):
]


from flask_appbuilder import ModelRestApi

class ContactModelApi(ModelRestApi):
resource_name = 'contact'
datamodel = SQLAInterface(Contact)
allow_browser_login = True
order_rel_fields = {
'contact_group': ('name', 'desc')
}

appbuilder.add_api(ContactModelApi)

db.create_all()
fill_gender()
appbuilder.add_view(
Expand Down

0 comments on commit 4a7f643

Please sign in to comment.