I have a ModelForm and a view, but the form's validation messages are
always rendered on first viewing - any idea why?

# ModelForm
class ContactForm( ModelForm ):
    first_name = CharField( 'Firstname' )
    last_name = CharField( 'Lastname' )
    company = CharField( 'Company' )
    tel = CharField( 'Telephone' )
    email = EmailField( 'Email' )
    message = CharField( 'Message', widget=Textarea )

    class Meta:
        model = Contact
        fields = ( 'first_name', 'last_name', 'company', 'tel',
'email', 'message', )

    def __init__(self, *args, **kwargs ):
        super( ContactForm, self ).__init__( args, kwargs )
        self.fields.keyOrder = self.Meta.fields

# View
def contact( request ):
    if request.method == 'POST':
        contact = ContactForm( request.POST, auto_id='contact_%s' )
        if contact.is_valid():
            contact.user = request.user
            contact.save()
            contact = None
    else:
        contact = ContactForm( auto_id='contact_%s' )
    return render_to_response( 'contact.html',
                    { 'contact' : contact, },
                    context_instance = RequestContext( request ) )
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to