Repository: flask-admin/flask-admin

Issue:
Flask admin peewee example failed to run with 2.8 version
I tried the Peewee integration [example](https://github.com/flask-admin/flask-admin/blob/master/examples/peewee/app.py) as plain as Copy pasting it and I am getting this error:

```
MY_ENV_PATH/bin/python "MY_PROJECT/bgadmin/app.py"
Traceback (most recent call last):
  File "MY_PROJECT/bgadmin/app.py", line 88, in <module>
    admin.add_view(UserAdmin(User))
  File "MY_ENV_PATH/lib/python2.7/site-packages/flask_admin/contrib/peewee/view.py", line 170, in __init__
    menu_icon_value=menu_icon_value)
  File "MY_ENV_PATH/lib/python2.7/site-packages/flask_admin/model/base.py", line 718, in __init__
    self._refresh_cache()
  File "MY_ENV_PATH/lib/python2.7/site-packages/flask_admin/model/base.py", line 810, in _refresh_cache
    self._refresh_forms_cache()
  File "MY_ENV_PATH/lib/python2.7/site-packages/flask_admin/model/base.py", line 735, in _refresh_forms_cache
    self._create_form_class = self.get_create_form()
  File "MY_ENV_PATH/lib/python2.7/site-packages/flask_admin/model/base.py", line 1147, in get_create_form
    return self.get_form()
  File "MY_ENV_PATH/lib/python2.7/site-packages/flask_admin/model/base.py", line 1100, in get_form
    return self.scaffold_form()
  File "MY_ENV_PATH/lib/python2.7/site-packages/flask_admin/contrib/peewee/view.py", line 264, in scaffold_form
    form_class = self.scaffold_inline_form_models(form_class)
  File "MY_ENV_PATH/lib/python2.7/site-packages/flask_admin/contrib/peewee/view.py", line 297, in scaffold_inline_form_models
    m)
  File "MY_ENV_PATH/lib/python2.7/site-packages/flask_admin/contrib/peewee/form.py", line 213, in contribute
    for field in info.model._meta.get_fields():
AttributeError: 'ModelOptions' object has no attribute 'get_fields'
```

The version of the libraries are: Flask 0.10.1, Flask-Admin 1.4.0, peewee 2.8.0

Thanks in advance



Discussion:
This problem may seem the same described in #1117 that was solved in #1125 but I am still getting this error. I downgraded Peewee to 2.7.4 but persisted. Any help will be appreciated, thanks in advance. 


Resolving patch:
diff --git a/flask_admin/contrib/peewee/form.py b/flask_admin/contrib/peewee/form.py
--- a/flask_admin/contrib/peewee/form.py
+++ b/flask_admin/contrib/peewee/form.py
@@ -10,7 +10,7 @@
 from flask_admin.model.form import InlineFormAdmin, InlineModelConverterBase
 from flask_admin.model.fields import InlineModelFormField, InlineFieldList, AjaxSelectField
 
-from .tools import get_primary_key
+from .tools import get_primary_key, get_meta_fields
 from .ajax import create_ajax_loader
 
 
@@ -210,7 +210,7 @@ def contribute(self, converter, model, form_class, inline_model):
 
         info = self.get_info(inline_model)
 
-        for field in info.model._meta.get_fields():
+        for field in get_meta_fields(info.model):
             field_type = type(field)
 
             if field_type == ForeignKeyField:
diff --git a/flask_admin/contrib/peewee/tools.py b/flask_admin/contrib/peewee/tools.py
--- a/flask_admin/contrib/peewee/tools.py
+++ b/flask_admin/contrib/peewee/tools.py
@@ -11,3 +11,11 @@ def parse_like_term(term):
         stmt = '%%%s%%' % term
 
     return stmt
+
+
+def get_meta_fields(model):
+    try:
+        fields = model._meta.sorted_fields
+    except AttributeError:
+        fields = model._meta.get_fields()
+    return fields


Test patch: