title: clean() method in model and field validation
body: <p>I have a problem with a model's <code>clean()</code> method and basic field validation. here's my model and the <code>clean()</code> method.</p>
  
  <pre><code>class Trial(models.Model):
  
      trial_start = DurationField()
      movement_start = DurationField()
      trial_stop = DurationField()
  
  
      def clean(self):
          from django.core.exceptions import ValidationError
          if not (self.movement_start &gt;= self.trial_start):
              raise ValidationError('movement start must be &gt;= trial start')
          if not (self.trial_stop &gt;= self.movement_start):
              raise ValidationError('trial stop must be &gt;= movement start')
          if not (self.trial_stop &gt; self.trial_start):
              raise ValidationError('trial stop must be &gt; trial start')
  </code></pre>
  
  <p>My <code>clean()</code> method checks whether certain values are in the correct range. If the user forget to fill out a field, e.g. <code>movement_start</code>, then I get an error:</p>
  
  <p><code>can't compare datetime.timedelta to NoneType</code></p>
  
  <p>I'm surprised that I get this error, since the original <code>clean()</code> function should be catching that missing entry (after all <code>movement_start</code> is a required field). So how can I the basic checking for missing values, and my custom check whether values are in certain ranges? Can this be done with model's <code>clean()</code> method, or do I need to use <code>Forms</code>?</p>
  
  <p><strong>EDIT1</strong> to make it more clear: <code>trial_start</code>, <code>movement_start</code> and <code>trial_stop</code> are all required fields. I need to write a <code>clean()</code> method which first checks that all three fields have been filled out, and then, check whether the values are in a certain range.</p>
  
  <p>The following code for example DOES NOT work, since <code>trial_start</code> might be empty. I want to avoid having to check for the existence of each field - django should do that for me.</p>
  
  <pre><code>class TrialForm(ModelForm):
  
      class Meta:
          model = Trial
  
      def clean_movement_start(self):
          movement_start = self.cleaned_data["movement_start"]
          trial_start = self.cleaned_data["trial_start"]
          if not (movement_start &gt;= trial_start):
              raise forms.ValidationError('movement start must be &gt;= trial start')
          return self.cleaned_data["movement_start"] 
  </code></pre>
  
  <p><strong>EDIT2</strong>  The reason that I wanted to add this check to the model's <code>clean()</code> method is that objects that are created on the python shell, will automatically be checked for correct values. A form will be fine for views, but I need the value check also for the shell.</p>