title: Django CreateView show error not working
body: <p>how i can prevent the Repetition of renting a car for the same period
  the car was already rented or reserved for ex : 01/01/2017  to 01/03/2017
  if i trie to rent this car for a period between this dates " 01/01/2017  to 01/03/2017" it should  give me a error like the validation error in the right of the field</p>
  
  <p><a href="https://i.stack.imgur.com/8GWzg.png" rel="nofollow noreferrer">screen shot for my rental car app</a></p>
  
  <p>models.py</p>
  
  <pre><code>class Car(models.Model):
  
      imatriculation = models.CharField(max_length=100, primary_key=True)
      marque = models.CharField(max_length=100)
      couleur = models.CharField(max_length=100)
  
  class Contra(models.Model):
  
      car = models.ForeignKey(Car, on_delete=models.CASCADE)
      date_debut = models.DateField(null=True ,blank=True)
      heure_debut = models.TimeField(null=True ,blank=True)
      date_retour = models.DateField(null=True ,blank=True)
      heure_retour = models.TimeField(null=True ,blank=True)
  </code></pre>
  
  <p>forms.py</p>
  
  <pre><code>class CarForm(forms.ModelForm):
  
      class Meta:
          model = Car
          fields = ('imatriculation', 'marque',  'couleur')       
  
  
  class ContraForm(forms.ModelForm):
  
      date_debut = forms.DateField(widget = AdminDateWidget())
      heure_debut = forms.TimeField(widget = AdminTimeWidget())
      date_retour = forms.DateField(widget = AdminDateWidget())
      heure_retour = forms.TimeField(widget = AdminTimeWidget())
  
      class Meta:
          model = Contra
          fields = ('car','date_debut','heure_debut',  
                   'date_retour','heure_retour')
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>class ContraCreate(CreateView):
      template_name = 'rentcar/contra_update.html'
      form_class = ContraForm
      model = Contra
  
      def form_valid(self, form):
                  now_date = date.today()
                  now_time = datetime.now().strftime('%H:%M:%S')
                  x = Contra.objects.filter(location=self.request.user,
                      date_debut__lte=now_date, date_retour__gte=now_date)
                  c = form.instance.car
                  for e in x:
                      if c.imatriculation ==  e.car.imatriculation :
                      print ("Leased car")
                      ValidationError(_('Invalid value'))
                      return super(ContraCreate, self).form_invalid(form)
                  return super(ContraCreate, self).form_valid(form) 
  </code></pre>
  
  <p>i find a solution using clean</p>
  
  <pre><code>def clean(self):
      super(ContratForm, self).clean()
      form_car          = self.cleaned_data.get('car')    
      form_date_debut   = self.cleaned_data.get('date_debut')
      form_date_retour  = self.cleaned_data.get('date_retour')
      form_heure_debut  = self.cleaned_data.get('heure_debut')
      form_heure_retour = self.cleaned_data.get('heure_retour')
      h                 = form_car.imatriculation
  
      x1  = Contrat.objects.filter(location=self.user,car=h ,date_debut__lte=form_date_debut,date_retour__gte=form_date_retour)
      x2  = Contrat.objects.filter(location=self.user,car=h ,date_debut__gt=form_date_debut,date_debut__lt=form_date_retour,date_retour__gte=form_date_retour)
      x25 = Contrat.objects.filter(location=self.user,car=h ,date_debut__gt=form_date_debut,date_debut=form_date_retour,heure_debut__lt=form_heure_retour)
      x3  = Contrat.objects.filter(location=self.user,car=h ,date_debut__lte=form_date_debut,date_retour__gt=form_date_debut,date_retour__lt=form_date_retour)
      x35 = Contrat.objects.filter(location=self.user,car=h ,date_debut__lte=form_date_debut,date_retour=form_date_debut,heure_retour__gt=form_heure_debut)
      x4  = Contrat.objects.filter(location=self.user,car=h ,date_debut__gt=form_date_debut,date_retour__lt=form_date_retour)
  
  
      if x1:
          for k in x1:
              self._errors['car']          = "Deja reserve .contrat %s" %(k.id)
              self._errors['date_debut']   = k.date_debut.strftime('%d/%m/%Y')
              self._errors['date_retour']  = k.date_retour.strftime('%d/%m/%Y')
      elif x2:
          for k in x2:
              self._errors['car']          = "Deja reserve .contrat %s" %(k.id)
              self._errors['date_retour']  = ("&lt;= %s" %(k.date_debut).strftime('%d/%m/%Y'))
      elif x25:
          for k in x25:
              self._errors['car']          = "Changer l'heur retour"
              self._errors['date_retour']  = ("= Date depart contrat %s" %(k.id))
              self._errors['heure_retour'] = ("&lt; %s" %(k.heure_debut))
      elif x3:
          for k in x35:
              self._errors['car']          = "Deja reserve .contrat %s" %(k.id)
              self._errors['date_debut']   = ("&gt;= %s" %(k.date_retour).strftime('%d/%m/%Y'))
      elif x35:
          for k in x35:
              self._errors['car']          = "Changer l'heur de depart"
              self._errors['date_debut']   = ("= Date debut contrat %s" %(k.id))
              self._errors['heure_debut']  = ("&gt; %s" %(k.heure_retour))
      elif x4:
          for k in x4:
              self._errors['car']          = "Deja reserve .contrat %s" %(k.id)
              self._errors['date_debut']   = k.date_debut.strftime('%d/%m/%Y')
              self._errors['date_retour']  = k.date_retour.strftime('%d/%m/%Y')
  
      return self.cleaned_data
  </code></pre>