On Tue, Jul 5, 2011 at 5:14 PM, candlerb <b.cand...@pobox.com> wrote: > 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: >
No, it doesn't have any model level validation. If you check the source, it is simply a char field with max length of 15 characters. It's form field does have validation though, and you can add the same validator used there as a validator on the model field: from django.core.validators import validate_ipv4_address ... ip = models.IPAddressField(..., validators=[validate_ipv4_address]) Also, as you can see in the name, this only supports IPv4. For a more complete solution (requires postgres) I use the excellent django-postgresql-netfields - https://github.com/adamcik/django-postgresql-netfields Cheers Tom -- 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.