or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

appengine-integration.mdcore-admin.mdfile-admin.mdforms.mdgeoalchemy-integration.mdhelpers-utilities.mdindex.mdmodel-views.mdmongoengine-integration.mdredis-integration.mdsqlalchemy-integration.md

appengine-integration.mddocs/

0

# Google App Engine Integration

1

2

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.

3

4

## Capabilities

5

6

### Model View Factory

7

8

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

9

10

```python { .api }

11

from flask_admin.contrib.appengine import ModelView

12

13

def ModelView(model):

14

"""

15

Factory function for creating App Engine model views.

16

17

Parameters:

18

- model: App Engine model class (DB or NDB)

19

20

Returns:

21

NdbModelView or DbModelView based on model type

22

23

Raises:

24

ValueError: If model is not a supported App Engine model

25

"""

26

```

27

28

### NDB Model View

29

30

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

31

32

```python { .api }

33

from flask_admin.contrib.appengine.view import NdbModelView

34

35

class NdbModelView(BaseModelView):

36

"""

37

App Engine NDB model view for modern datastore models.

38

39

Provides automatic scaffolding for NDB models with support for:

40

- URL-safe key handling

41

- Indexed property detection

42

- Form generation from model properties

43

- Pagination and sorting

44

"""

45

46

model_form_converter = AdminModelConverter

47

48

def get_pk_value(self, model):

49

"""Get URL-safe key for NDB model."""

50

51

def scaffold_list_columns(self):

52

"""Auto-detect NDB properties for list view."""

53

54

def scaffold_sortable_columns(self):

55

"""Detect indexed NDB properties for sorting."""

56

57

def get_list(self, page, sort_field, sort_desc, search, filters, page_size=None):

58

"""Retrieve paginated NDB model list with sorting."""

59

60

def get_one(self, urlsafe_key):

61

"""Retrieve single NDB model by URL-safe key."""

62

63

def create_model(self, form):

64

"""Create new NDB model instance."""

65

66

def update_model(self, form, model):

67

"""Update existing NDB model."""

68

69

def delete_model(self, model):

70

"""Delete NDB model by key."""

71

```

72

73

### Legacy DB Model View

74

75

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

76

77

```python { .api }

78

from flask_admin.contrib.appengine.view import DbModelView

79

80

class DbModelView(BaseModelView):

81

"""

82

App Engine DB model view for legacy datastore models.

83

84

Supports legacy DB API with:

85

- String-based key handling

86

- Property introspection

87

- Form scaffolding

88

- Basic CRUD operations

89

"""

90

91

def get_pk_value(self, model):

92

"""Get string representation of DB model key."""

93

94

def scaffold_list_columns(self):

95

"""Auto-detect DB properties for list view."""

96

97

def scaffold_sortable_columns(self):

98

"""Detect indexed DB properties for sorting."""

99

100

def get_list(self, page, sort_field, sort_desc, search, filters):

101

"""Retrieve paginated DB model list."""

102

103

def get_one(self, encoded_key):

104

"""Retrieve single DB model by encoded key."""

105

106

def create_model(self, form):

107

"""Create new DB model instance."""

108

109

def update_model(self, form, model):

110

"""Update existing DB model."""

111

112

def delete_model(self, model):

113

"""Delete DB model instance."""

114

```

115

116

### Form Conversion

117

118

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

119

120

```python { .api }

121

from flask_admin.contrib.appengine.form import AdminModelConverter

122

123

class AdminModelConverter:

124

"""

125

Form converter for App Engine model properties.

126

127

Converts App Engine property types to appropriate WTForms fields

128

using wtforms-appengine backend for proper datastore integration.

129

"""

130

```

131

132

### Custom Field Types

133

134

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

135

136

```python { .api }

137

from flask_admin.contrib.appengine.fields import AppEngineSpecificFields

138

139

# App Engine specific form fields for:

140

# - Key references

141

# - Blob properties

142

# - Text properties

143

# - User properties

144

```

145

146

## Usage Examples

147

148

### Basic NDB Model Administration

149

150

```python

151

from flask import Flask

152

from flask_admin import Admin

153

from flask_admin.contrib.appengine import ModelView

154

from google.appengine.ext import ndb

155

156

app = Flask(__name__)

157

admin = Admin(app)

158

159

# NDB model

160

class Article(ndb.Model):

161

title = ndb.StringProperty(required=True)

162

content = ndb.TextProperty()

163

author = ndb.StringProperty(indexed=True)

164

created = ndb.DateTimeProperty(auto_now_add=True)

165

published = ndb.BooleanProperty(default=False)

166

167

# Add NDB model view (automatically detects NDB)

168

admin.add_view(ModelView(Article, name='Articles'))

169

```

170

171

### Legacy DB Model Administration

172

173

```python

174

from google.appengine.ext import db

175

176

# Legacy DB model

177

class Comment(db.Model):

178

article_key = db.ReferenceProperty(Article)

179

author = db.StringProperty(required=True)

180

content = db.TextProperty(required=True)

181

created = db.DateTimeProperty(auto_now_add=True)

182

183

# Add DB model view (automatically detects DB)

184

admin.add_view(ModelView(Comment, name='Comments'))

185

```

186

187

### Custom NDB Model View

188

189

```python

190

from flask_admin.contrib.appengine.view import NdbModelView

191

192

class CustomArticleView(NdbModelView):

193

# List view configuration

194

column_list = ('title', 'author', 'created', 'published')

195

column_searchable_list = ('title', 'author')

196

column_filters = ('published', 'created')

197

198

# Form configuration

199

form_columns = ('title', 'content', 'author', 'published')

200

201

# Custom form field arguments

202

form_args = {

203

'title': {

204

'validators': [DataRequired(), Length(min=5, max=200)]

205

},

206

'content': {

207

'widget': TextAreaWidget(rows=10)

208

}

209

}

210

211

# Custom permissions

212

def is_accessible(self):

213

return current_user.is_admin()

214

215

# Custom model processing

216

def create_model(self, form):

217

model = super().create_model(form)

218

if model:

219

# Custom logic after model creation

220

self.send_notification(f"New article: {model.title}")

221

return model

222

223

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

224

```

225

226

### Mixed DB and NDB Administration

227

228

```python

229

# Using both legacy DB and modern NDB in same app

230

from flask_admin.contrib.appengine import ModelView

231

232

# NDB models

233

class User(ndb.Model):

234

username = ndb.StringProperty(required=True)

235

email = ndb.StringProperty(required=True)

236

created = ndb.DateTimeProperty(auto_now_add=True)

237

238

# Legacy DB models

239

class LegacyData(db.Model):

240

name = db.StringProperty(required=True)

241

value = db.TextProperty()

242

243

# Factory automatically creates appropriate views

244

admin.add_view(ModelView(User, name='Users (NDB)'))

245

admin.add_view(ModelView(LegacyData, name='Legacy Data (DB)'))

246

```

247

248

## Requirements

249

250

The App Engine integration requires additional dependencies:

251

252

```bash

253

pip install wtforms-appengine

254

```

255

256

This package provides:

257

- **wtforms-appengine**: WTForms integration for App Engine datatypes

258

- Automatic form field conversion for App Engine properties

259

- Support for both DB and NDB APIs

260

261

## Migration Notes

262

263

When migrating from DB to NDB API:

264

- Keys are handled differently (URL-safe vs. encoded strings)

265

- Property indexing behavior has changed

266

- Query syntax and capabilities differ

267

- Form scaffolding adapts automatically to the detected model type