CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-flask-admin

Simple and extensible admin interface framework for Flask

86

1.30x

Quality

Pending

Does it follow best practices?

Impact

86%

1.30x

Average score across 10 eval scenarios

Overview
Eval results
Files

appengine-integration.mddocs/

Google App Engine Integration

Google App Engine datastore integration providing admin interfaces for both legacy DB API and modern NDB API models. Supports automatic model scaffolding, form generation, and CRUD operations for App Engine applications.

Capabilities

Model View Factory

Automatic model view creation that detects the appropriate App Engine API and returns the corresponding view class.

from flask_admin.contrib.appengine import ModelView

def ModelView(model):
    """
    Factory function for creating App Engine model views.
    
    Parameters:
    - model: App Engine model class (DB or NDB)
    
    Returns:
    NdbModelView or DbModelView based on model type
    
    Raises:
    ValueError: If model is not a supported App Engine model
    """

NDB Model View

Modern NDB (next-generation datastore) model administration with automatic scaffolding and key-based operations.

from flask_admin.contrib.appengine.view import NdbModelView

class NdbModelView(BaseModelView):
    """
    App Engine NDB model view for modern datastore models.
    
    Provides automatic scaffolding for NDB models with support for:
    - URL-safe key handling
    - Indexed property detection
    - Form generation from model properties
    - Pagination and sorting
    """
    
    model_form_converter = AdminModelConverter
    
    def get_pk_value(self, model):
        """Get URL-safe key for NDB model."""
    
    def scaffold_list_columns(self):
        """Auto-detect NDB properties for list view."""
    
    def scaffold_sortable_columns(self):
        """Detect indexed NDB properties for sorting."""
    
    def get_list(self, page, sort_field, sort_desc, search, filters, page_size=None):
        """Retrieve paginated NDB model list with sorting."""
    
    def get_one(self, urlsafe_key):
        """Retrieve single NDB model by URL-safe key."""
    
    def create_model(self, form):
        """Create new NDB model instance."""
    
    def update_model(self, form, model):
        """Update existing NDB model."""
    
    def delete_model(self, model):
        """Delete NDB model by key."""

Legacy DB Model View

Legacy App Engine DB API model administration for older datastore applications.

from flask_admin.contrib.appengine.view import DbModelView

class DbModelView(BaseModelView):
    """
    App Engine DB model view for legacy datastore models.
    
    Supports legacy DB API with:
    - String-based key handling
    - Property introspection
    - Form scaffolding
    - Basic CRUD operations
    """
    
    def get_pk_value(self, model):
        """Get string representation of DB model key."""
    
    def scaffold_list_columns(self):
        """Auto-detect DB properties for list view."""
    
    def scaffold_sortable_columns(self):
        """Detect indexed DB properties for sorting."""
    
    def get_list(self, page, sort_field, sort_desc, search, filters):
        """Retrieve paginated DB model list."""
    
    def get_one(self, encoded_key):
        """Retrieve single DB model by encoded key."""
    
    def create_model(self, form):
        """Create new DB model instance."""
    
    def update_model(self, form, model):
        """Update existing DB model."""
    
    def delete_model(self, model):
        """Delete DB model instance."""

Form Conversion

Automatic form field conversion for App Engine property types using wtforms-appengine integration.

from flask_admin.contrib.appengine.form import AdminModelConverter

class AdminModelConverter:
    """
    Form converter for App Engine model properties.
    
    Converts App Engine property types to appropriate WTForms fields
    using wtforms-appengine backend for proper datastore integration.
    """

Custom Field Types

Specialized form fields for App Engine-specific data types and requirements.

from flask_admin.contrib.appengine.fields import AppEngineSpecificFields

# App Engine specific form fields for:
# - Key references
# - Blob properties  
# - Text properties
# - User properties

Usage Examples

Basic NDB Model Administration

from flask import Flask
from flask_admin import Admin
from flask_admin.contrib.appengine import ModelView
from google.appengine.ext import ndb

app = Flask(__name__)
admin = Admin(app)

# NDB model
class Article(ndb.Model):
    title = ndb.StringProperty(required=True)
    content = ndb.TextProperty()
    author = ndb.StringProperty(indexed=True)
    created = ndb.DateTimeProperty(auto_now_add=True)
    published = ndb.BooleanProperty(default=False)

# Add NDB model view (automatically detects NDB)
admin.add_view(ModelView(Article, name='Articles'))

Legacy DB Model Administration

from google.appengine.ext import db

# Legacy DB model
class Comment(db.Model):
    article_key = db.ReferenceProperty(Article)
    author = db.StringProperty(required=True)
    content = db.TextProperty(required=True)
    created = db.DateTimeProperty(auto_now_add=True)

# Add DB model view (automatically detects DB)
admin.add_view(ModelView(Comment, name='Comments'))

Custom NDB Model View

from flask_admin.contrib.appengine.view import NdbModelView

class CustomArticleView(NdbModelView):
    # List view configuration
    column_list = ('title', 'author', 'created', 'published')
    column_searchable_list = ('title', 'author')
    column_filters = ('published', 'created')
    
    # Form configuration
    form_columns = ('title', 'content', 'author', 'published')
    
    # Custom form field arguments
    form_args = {
        'title': {
            'validators': [DataRequired(), Length(min=5, max=200)]
        },
        'content': {
            'widget': TextAreaWidget(rows=10)
        }
    }
    
    # Custom permissions
    def is_accessible(self):
        return current_user.is_admin()
    
    # Custom model processing
    def create_model(self, form):
        model = super().create_model(form)
        if model:
            # Custom logic after model creation
            self.send_notification(f"New article: {model.title}")
        return model

admin.add_view(CustomArticleView(Article, name='Articles', category='Content'))

Mixed DB and NDB Administration

# Using both legacy DB and modern NDB in same app
from flask_admin.contrib.appengine import ModelView

# NDB models
class User(ndb.Model):
    username = ndb.StringProperty(required=True)
    email = ndb.StringProperty(required=True)
    created = ndb.DateTimeProperty(auto_now_add=True)

# Legacy DB models  
class LegacyData(db.Model):
    name = db.StringProperty(required=True)
    value = db.TextProperty()

# Factory automatically creates appropriate views
admin.add_view(ModelView(User, name='Users (NDB)'))
admin.add_view(ModelView(LegacyData, name='Legacy Data (DB)'))

Requirements

The App Engine integration requires additional dependencies:

pip install wtforms-appengine

This package provides:

  • wtforms-appengine: WTForms integration for App Engine datatypes
  • Automatic form field conversion for App Engine properties
  • Support for both DB and NDB APIs

Migration Notes

When migrating from DB to NDB API:

  • Keys are handled differently (URL-safe vs. encoded strings)
  • Property indexing behavior has changed
  • Query syntax and capabilities differ
  • Form scaffolding adapts automatically to the detected model type

Install with Tessl CLI

npx tessl i tessl/pypi-flask-admin

docs

appengine-integration.md

core-admin.md

file-admin.md

forms.md

geoalchemy-integration.md

helpers-utilities.md

index.md

model-views.md

mongoengine-integration.md

redis-integration.md

sqlalchemy-integration.md

tile.json