List Info

Thread: Need a little push with Newforms




Need a little push with Newforms
user name
2006-12-31 19:06:59
Hello,
I've done a bit of reading but still think I'm missing
something
fundamental . Could someone lend a hand? I'm trying to
display a form
based on my Project model, using the latest dev version of
Django. I
don't get any errors with the view below, but the template
refuses to
dump the form.as_p(), or as_table(), etc - it just leaves a
blank line.
Looking at the code for newforms, or the unit tests didn't
seem to
suggest what I'm doing incorrectly. Any tips would be
appreciated.

Thanks!
Bill.

views.py

from company.crm.models import Project
from django.shortcuts import render_to_response,
get_object_or_404
from django import newforms as forms

def addproject(request):
    if request.method == "GET":
        #f = ProjectForm()
        f = forms.form_for_model(Project)
        return render_to_response('crm/addproject.html',
{'theform':
f})
    elif request.method == "POST":
        pass
    else:
        pass


addproject.html
<html xmlns="http://www.w3.org/
1999/xhtml" xml:lang="en"
lang="en">

    <head>
        <title> CRM</title>
        <link href="http://localhost/sty
le.css" rel="stylesheet"
type="text/css" />
    </head>
    <body>
    <h1>CRM</h1>
    <h2>Add Projects</h2>
    {% if theform %}
        <form action = "addproject/" method =
"post">
        {{ theform.as_p }}
        <input type = "submit" />
        </form>
    {% endif %}
    </body>
</html>


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

Need a little push with Newforms
user name
2006-12-31 19:37:16
On 12/31/06, basementheadgmail.com
<basementheadgmail.com> wrote:
>         f = forms.form_for_model(Project)
>         return
render_to_response('crm/addproject.html', {'theform':
> f})

form_for_model() returns a Form class, not a Form instance.
You'll
have to instantiate the form class before sending it to the
template,
like so:

    ProjectForm = forms.form_for_model(Project)
    f = ProjectForm()
    return render_to_response('crm/addproject.html',
{'theform': f})

Adrian

-- 
Adrian Holovaty
holovaty.com | djangoproject.com

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

Need a little push with Newforms
user name
2006-12-31 21:53:03
Thanks Adran!
Very cool.

Bill.


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

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )