Hi everybody,

Explain me please what I'm doing wrong. So I'm trying to create a database and store data, that I get from django forms.
Everything looks fine, and when I manually check database it shows that it recieved a new row, however my browser gives me this message and do not redirect me:

AttributeError at /teacher/
'tuple' object has no attribute 'save'
Request Method: POST
Request URL:    http://127.0.0.1:8000/teacher/
Django Version: 1.3
Exception Type: AttributeError
Exception Value:    
'tuple' object has no attribute 'save'
Exception Location: /home/serg/python/Books/Books/../Books/BookList/views.py in teacher_form_page, line 107
Python Executable:  /usr/bin/python
Python Version: 2.7.2

here is my forms.py

class TeacherForm(forms.Form):
    name = forms.CharField(label='Name', widget=forms.TextInput(attrs={'size':64}))
    subject = forms.CharField(label='Subject', widget=forms.TextInput(attrs={'size':64}))
    rate = forms.IntegerField(label='Rate', widget=forms.TextInput(attrs={'size':1}))

here is my views.py

def teacher_form_page(request):
    if request.method == 'POST':
        form = TeacherForm(request.POST)
        if form.is_valid():
            teacher = Teachers.objects.get_or_create(
                name = form.cleaned_data['name'],
                subject = form.cleaned_data['subject'],
                rate = form.cleaned_data['rate'])
            teacher.save()           # that's where I'm getting error! (line 107)
            return HttpResponseRedirect("/")
    else:
        form = TeacherForm()
    variables = RequestContext(request, {'form': form})
    return render_to_response('teacher_save.html', variables)

here is my models.py

class Teachers(models.Model):
    name = models.CharField(max_length=64)
    subject = models.CharField(max_length=64)
    rate = models.IntegerField()

    def __str__(self):
        return self.name

here is my teacher_save.html

{% extends 'base.html' %}
{% block title %}Teachers{% endblock %}
{% block header %}Teacher Form{% endblock %}
{% block contents %}
    <form method="post" action=".">{% csrf_token %}
        {{ form.as_p }}
        <input type="submit" value="New Teacher" />
    </form>
{% endblock %}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.