Re: Missing/inconsistent GenericIPAddressField validation?
On Mon, Sep 7, 2015 at 12:33 PM, Hans S. Tømmerholtwrote: > GenericIPAddressField isn't intended to represent a CIDR address, which I > guess is what I'm trying to put into it. > > There is stuff like this: > https://pypi.python.org/pypi/django-netfields/0.2.1 +1 This is what we use for CIDR and arbitrary IP ranges, stored in postrgres as native types so that queries/filters all happen on the DB server with exceptional performance. > > I am still slightly confused as to why validation doesn't occur on the model > level, though. Validation only happens if you instruct it to happen. If you just save() the model instance, no validation occurs. See the "Note ..." paragraph here: https://docs.djangoproject.com/en/1.8/ref/models/instances/#validating-objects Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFHbX1%2BmgjY2%3DeX2Z53eFr7LBKwDeJRpR%3DQqRWUCLUmFsOoPaQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: Missing/inconsistent GenericIPAddressField validation?
On Mon, 07 Sep 2015 12:41:15 +0200, Hans S. Tømmerholtwrote: Hello. In a nutshell: It appears the validator applied to a GenericIPAddressField form field doesn't allow an IP address with a netmask. But saving the same thing to a PostgreSQL database via a model works just fine. As far as I can tell, both model and form fields use the same validators? Is this somehow expected? I'll answer some of my own questions. GenericIPAddressField isn't intended to represent a CIDR address, which I guess is what I'm trying to put into it. There is stuff like this: https://pypi.python.org/pypi/django-netfields/0.2.1 I am still slightly confused as to why validation doesn't occur on the model level, though. I got thrown by a different part of this app using GenericIPAddressField for a CIDR-value, which is working fine because it's never passed through a form. class IPAddressList(models.Model): address = models.GenericIPAddressField() class IPAddressListForm(ModelForm): class Meta: model = IPAddressList exclude = [] ip_address = "127.0.0.1/8" o = IPAddressList.objects.create(address=ip_address) print o.address # 127.0.0.1/8 But then: form = IPAddressListForm({"address": ip_address}) form.is_valid() print form.errors # addressEnter a valid IPv4 or IPv6 address. I'm using Django 1.8. I keep looking for stupid mistakes I might have made. Suggestions welcome. -- Best regards/vennlig hilsen Hans S. Tømmerholt Application Developer, Hosting, Global IT -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/op.x4lbpogz9xbofn%40hanst-laptop. For more options, visit https://groups.google.com/d/optout.
Missing/inconsistent GenericIPAddressField validation?
Hello. In a nutshell: It appears the validator applied to a GenericIPAddressField form field doesn't allow an IP address with a netmask. But saving the same thing to a PostgreSQL database via a model works just fine. As far as I can tell, both model and form fields use the same validators? Is this somehow expected? class IPAddressList(models.Model): address = models.GenericIPAddressField() class IPAddressListForm(ModelForm): class Meta: model = IPAddressList exclude = [] ip_address = "127.0.0.1/8" o = IPAddressList.objects.create(address=ip_address) print o.address # 127.0.0.1/8 But then: form = IPAddressListForm({"address": ip_address}) form.is_valid() print form.errors # addressEnter a valid IPv4 or IPv6 address. I'm using Django 1.8. I keep looking for stupid mistakes I might have made. Suggestions welcome. -- Best regards/vennlig hilsen Hans S. Tømmerholt Application Developer, Hosting, Global IT Opera Software -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/op.x4k9a1179xbofn%40hanst-laptop. For more options, visit https://groups.google.com/d/optout.