title: Django UpdateView using the validation of a custom create view
body: <p>SOLVED: Read Daniel Roseman's neat answer. It worked perfectly.</p>
  
  <p>I am not a very expert on Django: sorry if my question has a trivial answer.<br>
  I am using Django dev (1.8?).<br>
  My application manages the entries of certain <code>DATE</code> type which needs to be validated and coherent. Therefore in</p>
  
  <pre><code>views/create_fest.py
  </code></pre>
  
  <p>I have as follows:</p>
  
  <pre><code>class Formulario_nuevo_festivo(forms.ModelForm):
  
  class Meta:
      model = Festivo
      fields = ('nombre_festivo','fecha_unica','fecha_inicio','fecha_fin')
  def clean(self):
      cleaned_data=super(Formulario_nuevo_festivo,self).clean()
      fecha_unica     =cleaned_data.get("fecha_unica","")
      fecha_inicio    =cleaned_data.get("fecha_inicio","")
      fecha_fin       =cleaned_data.get("fecha_fin","")
      if fecha_unica and fecha_inicio and fecha_fin:
          raise forms.ValidationError(u"some message")
      elif not fecha_unica and not fecha_inicio and not fecha_fin:
          raise forms.ValidationError(u"some message")
      elif (fecha_unica and (fecha_inicio!=None or fecha_fin!=None)) or (fecha_inicio and not fecha_fin) or (fecha_fin and not fecha_inicio):
          raise forms.ValidationError(u"some message.")
      else:
          if (fecha_unica and (fecha_inicio==None or fecha_fin==None)):
              pass
          elif fecha_inicio &gt; fecha_fin or fecha_inicio==fecha_fin:
              raise forms.ValidationError(u"some message.")
          else:
              pass
      return cleaned_data
  
  def page(request):
      if request.POST:
          form = Formulario_nuevo_festivo(request.POST)
          if form.is_valid():
              form.save()
              return HttpResponseRedirect(reverse_lazy('listado_festivos'))
          else:
              return render(request, 'crear_festivo.html',{'form':form})
      else:
          form=Formulario_nuevo_festivo()
          return render(request,'crear_festivo.html',{'form':form})
  </code></pre>
  
  <p>which works perfectly: the validation works fine and the user can only create an object by accomplishing with the validation-
  The problem comes when i am using UPDATEVIEW to manage changes to this model:
  Here comes a piece of code inside of <code>views.py</code> snippet:</p>
  
  <pre><code>...
  class FestivoUpdateView(UpdateView):
  model           = Festivo
  fields          = ['nombre_festivo','fecha_unica','fecha_inicio','fecha_fin']
  template_name   = "editar_festivo.html"
  success_url     = reverse_lazy('listado_festivos')
  def post(self, request, *args, **kwargs):
      if "cancel" in request.POST:
          self.object = self.get_object()
          url = self.get_success_url()
          return HttpResponseRedirect(url)
      else:
          return super(FestivoUpdateView, self).post(request, *args, **kwargs)
  ...
  </code></pre>
  
  <p>The thing is that the user can enter whatever data into this UdateView with no kind of validation.  </p>
  
  <p>I have searched a lot (since I am not an english native speaker) but i am not having luck on finding an answer.<br>
  A lazy programmer would say "hey you could repeat the validation code in the views.py and do the validation again" but it would be against DRY philosophy and i am pretty sure there must be an easy way to force the UpdateView to use the create view validation.     </p>
  
  <p>What about if i put it someplace like "core/validate.py" and then import it as a function?
  I have no clue how to solute this, any help would be appreciate.<br>
   Thanks ahead</p>