I have a  model Foo and a corresponding FooForm with the requisite
inner Meta class and model=Foo.  I want a url example.com/newfoo to
bring up a blank form to allow the creation of a new Foo instance.  It
is not obvious to me how this should be done.  I reckon it is
something very roughly like:

project/urls.py:
===========
urlpatterns = patterns("", (r"/newfoo", project.views.newfoo))

project/views.py:
=============
def newfoo(request):
  if request.method == "GET":
    model = Foo()
    form = FooForm(instance=model)
    result = render_to_response("newfooform.html" {"form": form})
  elif request.method == "POST":
    form = FooForm(request.POST)
    form.save()

Does this, broadly speaking, sound correct?  My situation is
complicated by the fact that Foo contains many-to-many relationships
and some fields (e.g. username and timestamp) that need to be
populated by the handler, rather than taken from the HTML form (these
are in the "exclude" tuple on the form Meta definition).  Right now,
the form generated by FooForm is not useable.  It contains no
"verbose_name" labels on the fields, and so is undecipherable.

TIA

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

Reply via email to