diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 65b60a0..e639d0f 100644
a
|
b
|
class Field(object):
|
269 | 269 | """ |
270 | 270 | if not prepared: |
271 | 271 | value = self.get_prep_value(value) |
272 | | return value |
| 272 | if self.empty_strings_allowed: |
| 273 | return value |
| 274 | else: |
| 275 | return value or None |
273 | 276 | |
274 | 277 | def get_db_prep_save(self, value, connection): |
275 | 278 | "Returns field's value prepared for saving into a database." |
diff --git a/tests/regressiontests/model_fields/models.py b/tests/regressiontests/model_fields/models.py
index 45cd223..035fcd2 100644
a
|
b
|
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 | |
diff --git a/tests/regressiontests/model_fields/tests.py b/tests/regressiontests/model_fields/tests.py
index 72a7d4d..7798622 100644
a
|
b
|
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.TestCase):
|
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): |