File empty-ip-2.diff of Package python-django.openSUSE_12.1_Update

Empty ipaddress raises an error (invalid input syntax for type inet: "")

http://code.djangoproject.com/ticket/5622
Index: django/db/models/fields/__init__.py
===================================================================
--- django/db/models/fields/__init__.py.orig
+++ django/db/models/fields/__init__.py
@@ -917,6 +917,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"
 
Index: tests/regressiontests/model_fields/models.py
===================================================================
--- tests/regressiontests/model_fields/models.py.orig
+++ tests/regressiontests/model_fields/models.py
@@ -66,6 +66,9 @@ class BooleanModel(models.Model):
     bfield = models.BooleanField()
     string = models.CharField(max_length=10, default='abc')
 
+class IP(models.Model):
+    ip = models.IPAddressField(blank=True, null=True)
+
 ###############################################################################
 # FileField
 
Index: tests/regressiontests/model_fields/tests.py
===================================================================
--- tests/regressiontests/model_fields/tests.py.orig
+++ tests/regressiontests/model_fields/tests.py
@@ -1,3 +1,4 @@
+
 import datetime
 from decimal import Decimal
 
@@ -8,7 +9,7 @@ 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, IP
 
 # If PIL available, do these tests.
 if Image:
@@ -215,6 +216,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).
+        """
+        ip = IP.objects.create(ip="")
+        ip = IP.objects.get(pk=ip.pk)
+        self.assertEqual(ip.ip, None)
 
 class ValidationTest(test.TestCase):
     def test_charfield_raises_error_on_empty_string(self):
openSUSE Build Service is sponsored by