okay your first linked helped me...thank you !
I guess the documentaion is just too fragmented for me.
So now my view looks like this:
def main(request):
f = BuchungForm(request.POST)
return render_to_response('main/index.html', {'user' : request.user, 'form'
: f})
and my template looks like this:
..
<form action="/main/" method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit" />
</form>
...
This gives me almost the form that i wanted.
Now i did exclude certain fields in my form because i have to set them
automaticaly.
Eg. I have a field that's called Mitarbeiter. I want to set the field to the
current user id so i've tried this:
def main(request):
f = BuchungForm(request.POST)
buchung = f.save(commit=False)
buchung.Mitarbeiter = 'request.user.id'
buchung.save()
return render_to_response('main/index.html', {'user' : request.user, 'form'
: f})
but this gives me the following error:
could not be created because the data didn't validate.
It seems like as soon as i enter the site it tries co submit the data. Can i
somehow stop that from hapening. ?!
. . . . . . . . . . . . . . . . . . . . . . . . . .
Patrick Szabo
XSLT-Entwickler
LexisNexis
Marxergasse 25, 1030 Wien
mailto:[email protected]
Tel.: +43 (1) 534 52 - 1573
Fax: +43 (1) 534 52 - 146
-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] Im
Auftrag von Tom Evans
Gesendet: Montag, 14. Februar 2011 14:22
An: [email protected]
Betreff: Re: AW: Form to add data
How hard are you looking?
http://docs.djangoproject.com/en/1.2/topics/forms/
This page shows a clear example of how to use forms in general
http://docs.djangoproject.com/en/1.2/topics/forms/modelforms/
This page shows clear examples of how to use modelforms.
Cheers
Tom
--
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.