From c6de9aae64191232f6b81b31cd82dff159159210 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?B=C3=A9res=20Botond?= <botondus@gmail.com>
Date: Fri, 2 Mar 2012 00:17:14 +0200
Subject: [PATCH] Fixed patch to apply cleanly. Improved the changes to docs.
---
django/contrib/flatpages/models.py | 6 ++++--
django/db/models/fields/__init__.py | 2 --
docs/ref/models/fields.txt | 5 +++++
docs/releases/1.4.txt | 6 ++++++
tests/regressiontests/model_fields/tests.py | 7 +++++++
.../model_inheritance_regress/tests.py | 4 ++--
6 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/django/contrib/flatpages/models.py b/django/contrib/flatpages/models.py
index 85873ac..8563418 100644
a
|
b
|
class FlatPage(models.Model):
|
7 | 7 | url = models.CharField(_('URL'), max_length=100, db_index=True) |
8 | 8 | title = models.CharField(_('title'), max_length=200) |
9 | 9 | content = models.TextField(_('content'), blank=True) |
10 | | enable_comments = models.BooleanField(_('enable comments')) |
| 10 | enable_comments = models.BooleanField(_('enable comments'), default=False) |
11 | 11 | template_name = models.CharField(_('template name'), max_length=70, blank=True, |
12 | 12 | help_text=_("Example: 'flatpages/contact_page.html'. If this isn't provided, the system will use 'flatpages/default.html'.")) |
13 | | registration_required = models.BooleanField(_('registration required'), help_text=_("If this is checked, only logged-in users will be able to view the page.")) |
| 13 | registration_required = models.BooleanField(_('registration required'), |
| 14 | help_text=_("If this is checked, only logged-in users will be able to view the page."), |
| 15 | default=False) |
14 | 16 | sites = models.ManyToManyField(Site) |
15 | 17 | |
16 | 18 | class Meta: |
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 22546c2..666a390 100644
a
|
b
|
class BooleanField(Field):
|
555 | 555 | |
556 | 556 | def __init__(self, *args, **kwargs): |
557 | 557 | kwargs['blank'] = True |
558 | | if 'default' not in kwargs and not kwargs.get('null'): |
559 | | kwargs['default'] = False |
560 | 558 | Field.__init__(self, *args, **kwargs) |
561 | 559 | |
562 | 560 | def get_internal_type(self): |
diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt
index e34da13..e5f9c80 100644
a
|
b
|
If you need to accept :attr:`~Field.null` values then use
|
357 | 357 | would return their data as ``ints``, instead of true ``bools``. See the |
358 | 358 | release notes for a complete description of the change. |
359 | 359 | |
| 360 | .. versionchanged:: 1.4 |
| 361 | In previous versions of Django ``BooleanFields`` would have an implicit |
| 362 | default value of ``False``. Now it defaults to ``None`` if there is |
| 363 | no default specified. |
| 364 | |
360 | 365 | ``CharField`` |
361 | 366 | ------------- |
362 | 367 | |
diff --git a/docs/releases/1.4.txt b/docs/releases/1.4.txt
index 7b45f9e..f6ec185 100644
a
|
b
|
The internals of the tag aren't part of the official stable API, but in the
|
1042 | 1042 | interests of full disclosure, the ``ExtendsNode.__init__`` definition has |
1043 | 1043 | changed which may break any custom tags that use this node class. |
1044 | 1044 | |
| 1045 | ``BooleanField`` set to None when default value not specified |
| 1046 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 1047 | |
| 1048 | In previous versions of Django, a model's ``BooleanField`` would get ``False`` |
| 1049 | value when no default was provided. Now ``None`` value is used. |
| 1050 | |
1045 | 1051 | Features deprecated in 1.4 |
1046 | 1052 | ========================== |
1047 | 1053 | |
diff --git a/tests/regressiontests/model_fields/tests.py b/tests/regressiontests/model_fields/tests.py
index 8fe67fb..3774990 100644
a
|
b
|
class BooleanFieldTests(unittest.TestCase):
|
211 | 211 | select={'string_length': 'LENGTH(string)'})[0] |
212 | 212 | self.assertFalse(isinstance(b5.pk, bool)) |
213 | 213 | |
| 214 | def test_null_default(self): |
| 215 | # http://code.djangoproject.com/ticket/15124 |
| 216 | from django.db import IntegrityError |
| 217 | b = BooleanModel() |
| 218 | self.assertEqual(b.bfield, None) |
| 219 | self.assertRaises(IntegrityError, b.save) |
| 220 | |
214 | 221 | class ChoicesTests(test.TestCase): |
215 | 222 | def test_choices_and_field_display(self): |
216 | 223 | """ |
diff --git a/tests/regressiontests/model_inheritance_regress/tests.py b/tests/regressiontests/model_inheritance_regress/tests.py
index 8e2c56b..752386a 100644
a
|
b
|
class ModelInheritanceTest(TestCase):
|
180 | 180 | """ |
181 | 181 | Regression test for #6755 |
182 | 182 | """ |
183 | | r = Restaurant(serves_pizza=False) |
| 183 | r = Restaurant(serves_pizza=False, serves_hot_dogs=False) |
184 | 184 | r.save() |
185 | 185 | self.assertEqual(r.id, r.place_ptr_id) |
186 | 186 | orig_id = r.id |
187 | | r = Restaurant(place_ptr_id=orig_id, serves_pizza=True) |
| 187 | r = Restaurant(place_ptr_id=orig_id, serves_pizza=True, serves_hot_dogs=False) |
188 | 188 | r.save() |
189 | 189 | self.assertEqual(r.id, orig_id) |
190 | 190 | self.assertEqual(r.id, r.place_ptr_id) |