On 3/29/07, Frank <[EMAIL PROTECTED]> wrote:
> Are there more tutorials other than the one on the djangoproject site?
> Looking to use forms and how to fill dropdrown boxes from a database.

There are many here:
http://code.djangoproject.com/wiki/Tutorials
http://blixtra.org/blog/2006/07/17/top-30-django-tutorials-and-articles/

However, that's a fairly narrow request, and newforms is replacing
oldforms soon.  newforms are better and here in the long term, but not
well-documented yet because they are a work in progress.

In any case, you want something like this:

from django import newforms as forms
from your.models import YourModel

class MyForm(forms.Form):
   the_choice =
forms.ChoiceField(choices=YourModel.objects.filter(foo__exact='bar'))

In a view, you'd do this:

form = MyForm()

t = #your template

t.render(Context({form:form}))

And In your template, you'd have something like this:

{{ form.as_table }}

When round-tripping, you'd construct the form bound, like this:

form = MyForm(request.POST)

(MyForm expects a dictionary and binds any field to values in the dict
which match the field's name, and ignores any extra keys in the dict.)

If your head just exploded, sorry.  :)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to