On Mon, 07 Sep 2015 12:41:15 +0200, Hans S. Tømmerholt <ha...@opera.com> wrote:


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
# <ul class="errorlist"><li>address<ul class="errorlist"><li>Enter a valid IPv4 or IPv6 address.</li></ul></li></ul>

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.

Reply via email to