from flask_admin.contrib.peewee import ModelView
from flask.ext.admin import Admin
from flask_admin.contrib.peewee.form import CustomModelConverter
from flask_admin.form.widgets import DateTimePickerWidget
from playhouse.postgres_ext import ArrayField, DateTimeTZField
from wtforms import fields

from redash import models
from redash.permissions import require_permission


class PgModelConverter(CustomModelConverter):
    def __init__(self, view, additional=None):
        additional = {ArrayField: self.handle_array_field,
                      DateTimeTZField: self.handle_datetime_tz_field}
        super(PgModelConverter, self).__init__(view, additional)
        self.view = view

    def handle_array_field(self, model, field, **kwargs):
        return field.name, fields.StringField(**kwargs)

    def handle_datetime_tz_field(self, model, field, **kwargs):
        kwargs['widget'] = DateTimePickerWidget()
        return field.name, fields.DateTimeField(**kwargs)


class PgModelView(ModelView):
    model_form_converter = PgModelConverter

    @require_permission('admin')
    def is_accessible(self):
        return True


def init_admin(app):
    admin = Admin(app, name='re:dash')

    for m in models.all_models:
        admin.add_view(PgModelView(m))

@@ -288,16 +288,54 @@
 t fields
+%0Afrom wtforms.widgets import TextInput
 %0A%0Afrom r
@@ -406,16 +406,641 @@
 ssion%0A%0A%0A
+class ArrayListField(fields.Field):%0A    widget = TextInput()%0A%0A    def _value(self):%0A        if self.data:%0A            return u', '.join(self.data)%0A        else:%0A            return u''%0A%0A    def process_formdata(self, valuelist):%0A        if valuelist:%0A            self.data = %5Bx.strip() for x in valuelist%5B0%5D.split(',')%5D%0A        else:%0A            self.data = %5B%5D%0A%0A%0Aclass PasswordHashField(fields.PasswordField):%0A    def _value(self):%0A        return u''%0A%0A    def process_formdata(self, valuelist):%0A        if valuelist:%0A            self.data = models.pwd_context.encrypt(valuelist%5B0%5D)%0A        else:%0A            self.data = u''%0A%0A%0A
 class Pg
@@ -1433,21 +1433,17 @@
 me, 
-fields.String
+ArrayList
 Fiel

Use ArrayListField for Array fields.