开发者

Django Australian local flavor form validation

I'm having trouble getting django's django.contrib.localflavor.au.forms to validate my form input.

I have tried several ways to use the form widgets and have had no success. The form will display but not validate. Though it is very possible I'm doing something incorrect. My form code is as follows using a custom widget. Django version is 1.2.3

from django.contrib.localflavor.au.forms import AUStateSelect, AUPostCodeField, AUPhoneNumberField
...    
class ContactForm(ModelForm):
       class Meta:
          model = Contact
          fields = ('name', 'state')
          开发者_开发百科widgets = { 'state': AUStateSelect() }
          exclude = ['created']

I have also tried using a custom form field this way.

from django.contrib.localflavor.au.forms import AUStateSelect, AUPostCodeField, AUPhoneNumberField
...
    class ContactForm(ModelForm):
       class Meta:
          model = Contact
          exclude = ['created']
       state = AUStateSelect()

Either version does not display the select widget. No validation happens with AUPostCodeField or AUPhoneNumberField widgets either.

This is the code I use to add data to the database and check for valid input.

def addContact(request):
   if request.method == 'POST':
      contactForm = ContactForm(request.POST)

      if contactForm.is_valid():
         contactForm.save()

   return HttpResponseRedirect('scrapyard.views.main')

Thanks for your help.


class ContactForm(ModelForm):
       class Meta:
          model = Contact
          exclude = ['created']
          widgets = { 'state': AUStateSelect() }

Whether the order was involved or not this segment worked like a charm. Obviously an over site on my behalf.

Thanks everybody for your help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜