Created
June 13, 2011 18:37
-
-
Save jezdez/1023387 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py | |
| index 91ecbf2..18e62ef 100644 | |
| --- a/django/db/models/fields/__init__.py | |
| +++ b/django/db/models/fields/__init__.py | |
| @@ -928,6 +928,11 @@ class IPAddressField(Field): | |
| kwargs['max_length'] = 15 | |
| Field.__init__(self, *args, **kwargs) | |
| + def get_db_prep_value(self, value, connection, prepared=False): | |
| + if not prepared: | |
| + value = self.get_prep_value(value) | |
| + return value or None | |
| + | |
| def get_internal_type(self): | |
| return "IPAddressField" | |
| diff --git a/tests/regressiontests/model_fields/models.py b/tests/regressiontests/model_fields/models.py | |
| index 1dc1649..f75da1f 100644 | |
| --- a/tests/regressiontests/model_fields/models.py | |
| +++ b/tests/regressiontests/model_fields/models.py | |
| @@ -158,3 +158,6 @@ if Image: | |
| width_field='headshot_width') | |
| ############################################################################### | |
| + | |
| +class IPLog(models.Model): | |
| + ip = models.IPAddressField(blank=True, null=True) | |
| diff --git a/tests/regressiontests/model_fields/tests.py b/tests/regressiontests/model_fields/tests.py | |
| index b42c0af..a03ab31 100644 | |
| --- a/tests/regressiontests/model_fields/tests.py | |
| +++ b/tests/regressiontests/model_fields/tests.py | |
| @@ -8,7 +8,8 @@ from django.db import models | |
| from django.db.models.fields.files import FieldFile | |
| from django.utils import unittest | |
| -from models import Foo, Bar, Whiz, BigD, BigS, Image, BigInt, Post, NullBooleanModel, BooleanModel, Document | |
| +from models import (Foo, Bar, Whiz, BigD, BigS, Image, BigInt, Post, | |
| + NullBooleanModel, BooleanModel, Document, IPLog) | |
| # If PIL available, do these tests. | |
| if Image: | |
| @@ -224,6 +225,14 @@ class SlugFieldTests(test.TestCase): | |
| bs = BigS.objects.get(pk=bs.pk) | |
| self.assertEqual(bs.s, 'slug'*50) | |
| +class IPFieldTests(test.TestCase): | |
| + def test_ip_empty(self): | |
| + """ | |
| + Check it's possible to use empty values in IP field (#5622). | |
| + """ | |
| + log_entry = IPLog.objects.create(ip="") | |
| + log_entry = IPLog.objects.get(pk=log_entry.pk) | |
| + self.assertEqual(log_entry.ip, None) | |
| class ValidationTest(test.TestCase): | |
| def test_charfield_raises_error_on_empty_string(self): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment