Your Ad Here

Posts Tagged ‘db.expando’

Google App Engine Models Entities and Expandos

Sunday, April 13th, 2008

The models and entities framework for Google Apps is pretty fun. It is very similar to django models and ruby on rails but it is even more simplified. I have been playing with Google App Engine since it came out (was in first 10,000 yay!) and it is really fun. Prototypes have never been so rapid. I wish we got more than three apps to create, I have had to repurpose a few. I have lots of ideas I will be posting here and howtos.

To create a model:

class Person(db.Model):
  first_name = db.StringProperty()
  last_name = db.StringProperty()
  hobbies = db.StringListProperty()
 
p = Person(first_name="Albert", last_name="Johnson")
p.hobbies = ["chess", "travel"]
 
p.put() # creates/updates model and inserts data

To create an Expando model
Expando models are fun because they are dynamic. You can add properties to the classes on the fly and it expands automatically.

class Person(db.Expando):
  first_name = db.StringProperty()
  last_name = db.StringProperty()
  hobbies = db.StringListProperty()
 
p = Person(first_name="Albert", last_name="Johnson")
p.hobbies = ["chess", "travel"]
 
p.chess_elo_rating = 1350
 
p.travel_countries_visited = ["Spain", "Italy", "USA", "Brazil"]
p.travel_trip_count = 13
 
p.put() # creates/updates model and inserts data

Prototyping is extremely fast with Google App Engine. Python of course is always extremely fun to do. The winds are a changin’.

[ google app engine entities docs for the DatastoreAPI ]


drawcloud - cloud tracking, service and product development is proudly powered by WordPress
Entries (RSS) and Comments (RSS).
Your Ad Here Your Ad Here