Generation admin panel with custom column type in Websauna

107 views Asked by At

I have a SQLAlchemy model with custom type ChoiceType which comes from sqlalchemy_utils library.

class Recipient(Base, BaseMixin):
    first_name = Column(String())
    last_name = Column(String())
    social_network = Column(ChoiceType(SOCIAL_NETWOKRS))

Where SOCIAL_NETWOKRS are SOCIAL_NETWOKRS = [ ('vk', 'Vkontakte'), ('fb', 'Facebook'), ('youtube', 'Youtube'), ]

I got next error when going into admin panel for edit my model:

NotImplementedError: Not able to derive a colander type from sqlalchemy type: ChoiceType(length=255) Please explicitly provide a colander `typ` for the "social_network" Column.

How can I get around the restriction with saving autogeneration of the administrative panel?

1

There are 1 answers

3
eirenik0 On

I move from sqlalchemy_utils and add direct validation from a Colander.

Next snippet works as expected:

class Account(BaseMixin, Base):
    social_network = Column(String(), info={'colanderalchemy': {
        'typ': colander.String(),
        'widget': deform.widget.SelectWidget(values=SOCIAL_NETWOKRS),
    }})