Ticket #5622: empty-ip-2.diff
File empty-ip-2.diff, 2.4 KB (added by , 14 years ago) |
---|
-
django/db/models/fields/__init__.py
Empty ipaddress raises an error (invalid input syntax for type inet: "") http://code.djangoproject.com/ticket/5622
old new class IPAddressField(Field): 898 898 kwargs['max_length'] = 15 899 899 Field.__init__(self, *args, **kwargs) 900 900 901 def get_db_prep_value(self, value, connection, prepared=False): 902 if not prepared: 903 value = self.get_prep_value(value) 904 return value or None 905 901 906 def get_internal_type(self): 902 907 return "IPAddressField" 903 908 -
tests/regressiontests/model_fields/models.py
old new class BooleanModel(models.Model): 66 66 bfield = models.BooleanField() 67 67 string = models.CharField(max_length=10, default='abc') 68 68 69 class IP(models.Model): 70 ip = models.IPAddressField(blank=True, null=True) 71 69 72 ############################################################################### 70 73 # ImageField 71 74 -
tests/regressiontests/model_fields/tests.py
old new from django import forms 7 7 from django.db import models 8 8 from django.core.exceptions import ValidationError 9 9 10 from models import Foo, Bar, Whiz, BigD, BigS, Image, BigInt, Post, NullBooleanModel, BooleanModel 10 from models import Foo, Bar, Whiz, BigD, BigS, Image, BigInt, Post, NullBooleanModel, BooleanModel, IP 11 11 12 12 # If PIL available, do these tests. 13 13 if Image: … … class SlugFieldTests(django.test.TestCas 214 214 bs = BigS.objects.get(pk=bs.pk) 215 215 self.assertEqual(bs.s, 'slug'*50) 216 216 217 class IPFieldTests(django.test.TestCase): 218 def test_ip_empty(self): 219 """ 220 Check it's possible to use empty values in IP field (#5622). 221 """ 222 ip = IP.objects.create(ip="") 223 ip = IP.objects.get(pk=ip.pk) 224 self.assertEqual(ip.ip, None) 217 225 218 226 class ValidationTest(django.test.TestCase): 219 227 def test_charfield_raises_error_on_empty_string(self):