I'm pretty new to Django and Python and I've had some success from
reading some books and guides playing around so far but I'm having
trouble figuring out how to get data I submit from a form to save into
the database. I've simplified down my code to just the basics and I
can get the form to submit fine and get passed the "if form.isvalid()"
step, but I'm lost from there. I've looked at a ton of code samples,
but most are way too complex and I can't figure out the basics of
this. All I want to do is save the title field as a new database entry
in the shows_show table. Anybody out there willing to take a look at
this incredibly simple code and give me a pointer or two about what is
wrong, what I need to add to get that working.

Thanks a ton. - Andy

3 pertinent files:

models.py
---------
from django.db import models
from django import forms

class Show(models.Model):
    title = models.CharField(max_length=100)

class AddShow(forms.Form):
    title = forms.CharField(max_length=100)


views.py
--------
from django.http import HttpResponseRedirect
from tvolt.shows.models import Show, AddShow

def add(request):
    if request.method == 'POST':
        form = AddShow(request.POST)
        if form.is_valid():
            return HttpResponseRedirect('/shows/#success')
    return HttpResponseRedirect('/shows/#error')

index.html
----------
<form method="post" action="add/">
        <fieldset>
                <legend>Add a show</legend>
                <dl>
                        <dt><label for="id_title">Title</label></dt>
                        <dd>
                                <input id="id_title" type="text" name="title"
maxlength="100" />
                        </dd>
                        <dd>
                                <button type="submit">Add a show</button>
                        </dd>
                </dl>
        </fieldset>
</form>
--~--~---------~--~----~------------~-------~--~----~
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