[Answer]-Validation fails when customizing django form in template

1👍

First I would recommend updating the form definitions to include a label and a help_text. I don’t know which version you are using but here is a good place to start: https://docs.djangoproject.com/en/1.6/topics/forms/

Then, in the template you can just do {{ form.start_date.label_tag }}, {{ form.start_date }}, and {{ form.start_date.help_text }} whenever you want to place those into the form.

Second, for the validation issue, you might, instead of overriding clean, override clean_fieldname. In your case clean_start_date and clean_end_date. Once you have those set up for can do

def clean_end_date(self):
    start = self.cleaned_data['start_date'] 
    end = self.cleaned_data['end_date'] 

    if start > end:
        ...do stuff...

Leave a comment