Skip to content

SQLAlchemy Fields

sqlalchemy.SQLAlchemyFieldsSchema auto-generates fields from a SQLAlchemy model. Use it as table_schema or table_filters in SQLAlchemyAdmin.

Replacement for FieldsSchema that reads column types from the model and creates matching fields automatically.

ParameterDescription
model requiredSQLAlchemy model class

Auto-generated schema

If no fields list is set, all columns and relationships from the model will be included.

table_schema = sqlalchemy.SQLAlchemyFieldsSchema(model=User)

Type mapping

SQLAlchemy typeField
Integer, BigIntegerIntegerField
StringStringField (with max_length from column length)
BooleanBooleanField
DateTimeDateTimeField
NumericIntegerField (with precision and scale)
JSONJSONField
ARRAYArrayField
Foreign keySQLAlchemyRelatedField
RelationshipSQLAlchemyRelatedField

Model Column info

Use the info dict on SQLAlchemy columns to set field metadata:

import sqlalchemy as sa


class User(Base):
    __tablename__ = 'users'

    id = sa.Column(sa.Integer, primary_key=True)
    username = sa.Column(sa.String(100), info={'label': 'Username'})
    role = sa.Column(sa.String(20), info={
        'label': 'Role',
        'choices': RoleEnum,
    })
keyDescription
labelDisplay name for the field
help_textTooltip text
choicesEnum class — renders as ChoiceField

TIP

For example of enum choice see ChoiceField

AI/LLM: Documentation index available at https://docs.brilliance-admin.com/llms.txt