Formatting Django Forms

77 views
Skip to first unread message

codingJoe

unread,
Jul 20, 2008, 1:36:04 AM7/20/08
to Google App Engine

I am trying to build a form to insert data. I'm trying to use the
Django forms to for data entry.

My problem is that I want the user to enter a large description in a
large (250 character) text field. and larger if possible. The
automatic form the Django creates only gives me a 25 character field.


My 'fooDesc' field is puny! I want it to be a large. multi-line data
entry? much like the Groups discussion field I'm typing in right
now. How do I make my forms setup produce a large multi-line user-
entry text field?


Advice?

-------------------------python code-------------------------------
class Foo(db.Model):
fooText = db.StringProperty(required=True, default="I am Foo")
fooData = db.StringProperty(required=False, default="I am Foo
StringProperty")
fooDesc = db.TextProperty(required=False) # Large description
'Story' about Foo


class FooForm(djangoforms.ModelForm):
fooDesc = forms.CharField(max_length = 250)
class Meta:
model = Foo

class NewFoo(BaseRequestHandler):
def get(self):
self.generate('newFoo.html', {
'page': 'main',
'fooForm' : FooForm()
})

-------------------------end python
code-------------------------------



-------------------------html code-------------------------------

{% block body %}
<div class="story">
<p><strong>Instructions:</strong> enter the information to build a
new foo. </p>
</div>

<strong>Note! the fooDesc field is puny! I want it to be a
large. multi-line data entry? much like the Groups discussion field
I'm typingin now. </strong>

<form method="POST" action="/newFoo">
<table> {{ fooForm }} </table>
<input type="submit">'
</form>
{% endblock %}

-------------------------end html code-------------------------------

David Symonds

unread,
Jul 20, 2008, 1:45:28 AM7/20/08
to google-a...@googlegroups.com
On Sun, Jul 20, 2008 at 3:36 PM, codingJoe <codi...@gmail.com> wrote:

> class FooForm(djangoforms.ModelForm):
> fooDesc = forms.CharField(max_length = 250)
> class Meta:
> model = Foo

Your choice of forms.CharField is probably unwise here. Try
forms.Field(widget=forms.Textarea)


Dave.

codingJoe

unread,
Jul 20, 2008, 1:53:59 AM7/20/08
to Google App Engine


>
> Your choice of forms.CharField is probably unwise here. Try
> forms.Field(widget=forms.Textarea)

Thanks!

How do I specify a x,y size for the text area? And do you recommend a
reference I should read build more elegant Django forms?

David Symonds

unread,
Jul 20, 2008, 7:14:52 AM7/20/08
to google-a...@googlegroups.com

I just read the source code, under google_appengine/lib/django (look
for newforms). The Django website is probably a good place to start,
too.


Dave.

Reply all
Reply to author
Forward
0 new messages