I have a model defined as follows with an IPAddressField:

~~~~
class Nas(models.Model):
    name = models.CharField(max_length=128)
    ip = models.IPAddressField('IP Address', max_length=15,
unique=True)
    nas_type = models.CharField('NAS Type', max_length=32, blank=True)
    huntgroup = models.ForeignKey(Huntgroup)

    class Meta:
        verbose_name = "NAS"
        verbose_name_plural = "NASes"

    def __unicode__(self):
        return self.name + " (" + self.ip + ")"
~~~~

However, the model doesn't seem to validate that the ip field is a
valid IP address. Example:

>>> n = Nas(ip='wibble', name='bibble', huntgroup_id=12)
>>> n.full_clean()
>>> n.ip
'wibble'
>>>

However, it does validate other things, e.g. the presence of required
fields.

>>> n = Nas(ip='wibble', huntgroup_id=12)
>>> n.full_clean()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python2.6/dist-packages/Django-1.3-py2.6.egg/
django/db/models/base.py", line 828, in full_clean
    raise ValidationError(errors)
ValidationError: {'name': [u'This field cannot be blank.']}

is this a bug, or am I using it wrongly? I want to create models in
code, not in a form, but validate them before saving.

Thanks,

Brian.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to