0.3.4
Using select_schema to Exclude Fields from Read Operations
Some database field types can cause issues in admin panels. The most common example is PostgreSQL's TSVector type used for full-text search, which can trigger NotImplementedError when trying to display records.
The select_schema parameter allows you to exclude problematic fields from all read operations while keeping them available for create/update operations.
Use select_schema when you encounter:
- TSVector fields causing
NotImplementedErrorin admin views - Large binary fields that slow down list views
- Computed fields that don't need to be displayed
- Sensitive fields that should be hidden from admin users
- Complex JSON fields that break admin display formatting
Basic Example: Excluding TSVector Fields
from sqlalchemy import Column, Integer, String, Text
from sqlalchemy_utils import TSVectorType
from pydantic import BaseModel
from typing import Optional
from datetime import datetime
# SQLAlchemy model with TSVector for full-text search
class Document(Base):
__tablename__ = "documents"
id = Column(Integer, primary_key=True)
title = Column(String(200), nullable=False)
content = Column(Text, nullable=False)
created_at = Column(DateTime, default=func.now())
# This field causes NotImplementedError in admin views
search_vector = Column(TSVectorType('title', 'content'))
# Schemas for create/update (no search_vector)
class DocumentCreate(BaseModel):
title: str = Field(..., min_length=1, max_length=200)
content: str = Field(..., min_length=1)
class DocumentUpdate(BaseModel):
title: Optional[str] = Field(None, min_length=1, max_length=200)
content: Optional[str] = None
# Schema for read operations (excludes problematic field)
class DocumentSelect(BaseModel):
id: int
title: str
content: str
created_at: datetime
# search_vector field intentionally excluded!
# Register with admin
admin.add_view(
model=Document,
create_schema=DocumentCreate,
update_schema=DocumentUpdate,
select_schema=DocumentSelect, # ✅ TSVector excluded from reads
allowed_actions={"view", "create", "update", "delete"}
)What's Changed
- select_schema functional by @igorbenav in #32
Full Changelog: v0.3.3...v0.3.4