El error es al mostrar el formulario, y dice:
----------------------------------------
NameError at /new_book/
name 'TITLE_CHOICES' is not defined
Request Method: GET
Request URL: http://127.0.0.1:8000/new_book/
Django Version: 1.3.1
Exception Type: NameError
Exception Value:
name 'TITLE_CHOICES' is not defined
Tengo los codigos como sigue:
cms/mysite/models.py
Código Python:
cms/mysite/forms.pyVer original
from django.db import models from django.forms import ModelForm TITLE_CHOICES = ( ('MR', 'mr.'), ('MRS','Mrs.'), ('MS','Ms.'), ) class Author(models.Model): name = models.CharField(max_length=100) title = models.CharField(max_length=3, choices=TITLE_CHOICES) birth_date = models.DateField(blank=True, null=True) def __unicode__(self): return self.name class Book(models.Model): name = models.CharField(max_length=100) authors = models.ManyToManyField(Author) class AuthorForm(ModelForm): class Meta: model = Author class BookForm(ModelForm): class Meta: model = Book
Código Python:
Ver original
from django import forms class AuthorForm(forms.Form): name = forms.CharField(max_length=100) title = forms.CharField(max_length=3, widget=forms.Select(choices=TITLE_CHOICES)) birth_date = forms.DateField(required=False) class BookForm(forms.Form): name = forms.CharField(max_length=100) authors = forms.ModelMultipleChoiceField(queryset=Author.objects.all())
cms/mysite/views.py
Código Python:
Ver original
# Create your views here. from django.template.loader import get_template from django.template import Context from django.http import HttpResponse from forms import BookForm def new_book(request): if request.method == 'POST': form = BookForm(request.POST) if form.is_valid(): return HttpResponseRedirect('/new_book/thanks/') else : form = BookForm() return render_to_response('new_book.html',{'form':form,})
y las urls los tengo asi:
Código Python:
Ver original
from cms.mysite import views urlpatterns = patterns('', (r'^new_book/$', views.new_book), )
----------------------------
cms/mysite/templates/new_book.html