google models and django models different – limitations if I use django’s model

The following are occasional notes on Django App Engine non-rel functionality.

I tested that the native app engine data model was working correctly, and I was able to see the records created in the administrative console.

I added an object subclassed from django.db.models. At first I thought it wasn’t working because I was looking for the table name to follow the same convention as the native google.appengine.ext.db did, i.e., the object type and the entity name match. That is NOT the case for the django models. The name took the form project_typename. Once I understood what I was looking at, I saw that the object was stored correctly.

One concern: the data type objects are different between the Django models and the Google App Engine models. For example, in the native Google model, the first_name is:
first_name = db.StringProperty()
In the equivalent Django model, the data type is:
first_name = models.CharField(max_length=30)
This makes the code completely incompatible unless I wrapper everything, which I’m not going to do.

The concern is that I’m going to want to use Google types and won’t be able to down the road. To test how this is going to work, I’m going to try to interface a Google Contact object into the Big Table using Django models.

A taste of the code:

# cmap.views
# Copyright 2010 Eric A. Brooks.

“””Handle the various views for the polls module”””
import os
from django.http import HttpResponse
from django.shortcuts import render_to_response, get_object_or_404
from google.appengine.ext import db
from uuid import uuid4
from django.db import models

class AppUser(db.Model):
“””Model a user in the system.
Call: /newUser
No parameters
“””
rec_id = db.StringProperty()
domain = db.StringProperty()
first_name = db.StringProperty()
middle_name = db.StringProperty()
last_name = db.StringProperty()

def reset(self):
self.rec_id = “000”
self.domain = “”
self.first_name = “”
self.middle_name = “”
self.last_name = “”

class DjangoAppUser(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)

def newrec():
rec_id = uuid4().hex
rec = AppUser(key_name = rec_id)
rec.first_name = “Frank”
rec.middle_name = “Horatio”
rec.last_name = “Johnson”
rec.rec_id = rec_id
rec.put()

r2 = DjangoAppUser()
r2.first_name = “Beluga”
r2.last_name = “Whale”
r2.save()

def index(request):
“””Populate and return templates/cmap/index.html””” #return HttpResponse(“hello, world”)
newrec()
return render_to_response(‘cmap/index.html’, {‘nothing’: ‘nada’ })

Advertisements

About rico49

Writer, progresive activist, open source software developer. Working to meet the needs of under- and un-employed people globally and in the United States.
Gallery | This entry was posted in Google App Engine, Python. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s