appengine_admin
is a flexible datastore admin for app engine. MIT licensed.
This is a fork from the original mirror that is now different enough to justify not being an official fork :)
-
Download this repository's source and copy the
appengine_admin/
folder at the root of your App Engine project directory. -
Install gae_paginator and gae_csrf and configure their settings:
import appengine_admin appengine_admin.admin_settings.PAGINATOR_PATH = 'path.to.paginator.Paginator' appengine_admin.admin_settings.CSRF_HANDLER_PATH = 'path.to.gae_csrf.handlers.CSRFRequestHandler'
-
Update your app.yaml to add the URLs:
- url: /appengine_admin_media static_dir: appengine_admin/media # Your custom handler goes here (see next step) - url: /admin/models.* script: handlers.admin.app secure: always
-
Use it in your handlers (full working example):
import appengine_admin from webapp2 import RequestHandler, WSGIApplication # Declare your models. from google.appengine.ext import db class Artist(db.Expando): name = db.StringProperty() birthday = db.DateTimeProperty() class Album(db.Expando): name = db.StringProperty() release_year = db.StringProperty(default='2012') price = db.IntegerProperty() class Song(db.Expando): title = db.StringProperty() genre = db.StringProperty() album = db.ReferenceProperty(Album) artist = db.ReferenceProperty(Artist) # Register the appengine admin models. class AdminSong(appengine_admin.ModelAdmin): model = Song list_fields = ['title', 'genre', 'album'] readonly_fields = ['artist'] paginate_on = ['title'] appengine_admin.admin_settings.PAGINATOR_PATH = 'path.to.paginator.Paginator' appengine_admin.register(AdminSong) app = WSGIApplication( routes=appengine_admin.get_application_routes(), config=app_config, debug=DEBUG)
-
To configure your settings, look at
admin_settings.py
Custom settings below (TODO: move to separate doc).
Allow custom actions before initializing or saving the form, or after saving the form.
You can have a custom callback function to validate an individual field, example:
```python
from django import forms
class AdminSong(ModelAdmin):
# ...
def clean_title(self):
title = self.cleaned_data.get('title')
# do something here
if len(title) < 5:
raise forms.ValidationError('Title too short, must be at least 5 characters.')
return title
custom_clean = {
'title': clean_title,
}
```
-
Remember to update your index.yaml for each model class you are paginating. If you're just paginating by key, this should work:
- kind: Song properties: - name: __key__ direction: desc
TODO: add features
Most features are the ones listed on the now too-outdated-to-be-genuine-fork fork Appengine Admin project page.
There may be more to come.
- Why use it? To get a nice admin to manage your data on production. And because it's better than updating your data from the remote shell or the built-in datastore viewer. And because it's hopefully gonna get even better :)
See the Issues on GitHub for details. And help out!