class BookForm (forms.Form): name = forms.CharField (max_length = 1024, label = u"Book Title") date = forms.DateField (initial = date.today (), label = u"Issue Date") author = forms.ChoiceField ( choices = [(author.id, author.name) for author in Authors.all ()], label = u"First Author") description = forms.CharField ( widget = forms.Textarea, required = False, label = u"Description") def book_view (request): "Book view." if request.method == "POST": form = BookForm (request.POST) if form.is_valid (): book = Book ( name = form.cleaned_data ["name"], date = form.cleaned_data ["date"], authors = [get_object_or_404 (Authors, form.cleaned_data ["author"])] description = form.cleaned_data ["description"]) book.save () return redirect ("author", author_id = book.authors [0]) form = BookForm () return render_to_response ("book.html", {"form" : form})
<form action="{% url book %}" method="post"> <table> {{ form.as_table }} <tr> <th></th> <td><input type="submit" value="Enter" /></td> </tr> </table> </form>