views:

95

answers:

1

I have a very simple model:

class Artist(models.Model):
 name = models.CharField(max_length=64, unique=False)
 band = models.CharField(max_length=64, unique=False)
 instrument = models.CharField(max_length=64, unique=False)

 def __unicode__ (self):
  return self.name

that I'm using as a model form:

from django.forms import ModelForm 
from artistmod.artistcat.models import *

class ArtistForm(ModelForm):
 class Meta:
  model = Artist

but I can't seem to construct a view that will save the form data to the database. Currently I'm using:

def create_page(request):
    if request.method == 'POST':
            form = ArtistForm(request.POST) 
            if form.is_valid(): 
                    form.save()
                    return render_to_response('display.html')
    else:
            form = ArtistForm()
    return render_to_response('create.html', {
        'form': form,
})

can anyone help the newbie?

+1  A: 

Apparently the problem resided in my template. I was using

    <form action="display/" method="POST">

as opposed to

    <form action="." method="POST">

also changed my HttpRequest object from render_to_response to HttpResponseRedirect

true newbie errors but at least it works now

Glad you solved it. I personally prefer `action=""` so you don't lose the querystring on the POST.
SmileyChris
great note. was unaware of that. thanks SC!