title: Where to put validator for Django model field?
body: <p>The Django documentation shows an <a href="https://docs.djangoproject.com/en/1.5/ref/validators/" rel="nofollow">example</a> of a custom validator for a model field.  However the doc doesn't say where to put the validator function in your code.  If I put it in my models.py file in either location (as shown below), I get this error when I try to start the server:</p>
  
  <pre><code>NameError: name 'validate_name' is not defined
  </code></pre>
  
  <p>Where is the right location for this validate_name function?  Thanks.</p>
  
  <pre><code># models.py, example 1
  from django.db import models
  from django.core.exceptions import ValidationError
  
  class CommentModel(models.Model):
      # I get the error if I define the validator here
      def validate_name(value):
          if value == '':
              raise ValidationError(u'%s cannot be left blank' % value)
  
      name = models.CharField(max_length=25, validators=[validate_name])
  
  
  # models.py, example 2
  from django.db import models
  from django.core.exceptions import ValidationError
  
  # I also get the error if I define the validator here
  def validate_name(value):
      if value == '':
          raise ValidationError(u'%s cannot be left blank' % value)
  
  class CommentModel(models.Model):
      name = models.CharField(max_length=25, validators=[validate_name])
  </code></pre>