djangoforms

3 views
Skip to first unread message

Tim Riley

unread,
Oct 19, 2009, 9:09:15 PM10/19/09
to Google App Engine Oil
Hi:

I'm new to gaeo from app-engine-patch. I'm hoping to use
'djangoforms.ModelForm' with gaeo to ease development but I'm having a
tough time wrapping my head around it. Is it even possible? if so can
someone provide me with a simple example? It would be greatly
appreciated.


Tim

ericsk

unread,
Oct 19, 2009, 9:11:30 PM10/19/09
to Google App Engine Oil
Of course you can use djangoforms. It's not depedented by gaeo.

Just import it and use it :)

Tim Riley

unread,
Oct 19, 2009, 9:45:01 PM10/19/09
to google-app...@googlegroups.com
Eric:

I tried doing and I'm receiving an exception when I go to /foo/add

****************************************************************
Internal Server Error

Exception: invalid action

Traceback

Traceback (most recent call last):
dispatcher.py:176 in dispatch File
"C:\Users\riley\Documents\test\gaeo\dispatch\dispatcher.py", line 176,
in dispatch
raise Exception('invalid action')
Exception: invalid action
****************************************************************

I have attached a test program; if you could take a look and tell me
what I'm doing wrong I would appreciate it.

Tim Riley
test.zip

homiez

unread,
Nov 11, 2009, 8:25:49 AM11/11/09
to Google App Engine Oil
Hello, I'm new to GAEO from RoR. So I'm new to use python too.
But these day I like python because I found GAEO. Thanks for your
effort, Eric.

Anyway, I tried to use djangoforms. I can make it!
So this is simple sample.

(1) At Terminal
gaeogen scaffold Testform index new create show

(2) Make model(at application/mode/testform.py)

from google.appengine.ext import db
from gaeo.model import BaseModel, SearchableBaseModel

class Testform(BaseModel):
name = db.StringProperty(required=True)
secret = db.StringProperty(required=False)
phone = db.PhoneNumberProperty(required=True)
post_at = db.DateTimeProperty(required=True, auto_now_add=True)

(3)Make controller(at application/controller/testform.py)

import cgi
from google.appengine.ext import db
from gaeo.controller import BaseController
from model.testform import Testform
from google.appengine.ext.db import djangoforms

class TestformController(BaseController):
def create(self):
data = AddForm(data=self.request.POST)
if data.is_valid:
entity = data.save(commit=False)
entity.update_attributes(secret= "foo")
self.redirect('/testform')
else:
self.redirect('/testform/new')

def index(self):
query = Testform.all()
self.result = query.fetch(limit=1000)

def new(self):
self.form = AddForm()

def show(self):
self.r = Testform.get(self.params.get('id'))


class AddForm(djangoforms.ModelForm):
class Meta:
model = Testform
exclude = ['secret']

(4)Make new.html(At application/templates/new.html) : you just add
only {{ form }}

{% extends "../base.html" %}
{% block title %}TestformController#new{% endblock %}
{% block content %}
<form action="/testform/create" method="post">
<fieldset>
<legend>New Testform</legend>
{{ form }}
<p><input type="submit" value="Submit"></p>
</fieldset>
</form>
{% endblock %}

(5)Make show.html(At application/templates/show.html) :

{% extends "../base.html" %}
{% block title %}TestformController#show{% endblock %}
{% block content %}
{{ r.name }}:{{ r.phone }}:{{ r.secret }}
{% endblock %}


--------------------- finish! ------------------------
Enjoy!

homiez
myblog: homiezway.blogspot.com
>  test.zip
> 73K表示ダウンロード
Reply all
Reply to author
Forward
0 new messages