Skip to content

Commit

Permalink
Fixed #5563: BooleanField(null=True) now raises a validation warnin…
Browse files Browse the repository at this point in the history
…g telling users to use `NullBooleanField` instead. Thanks, SamBull.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@10456 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jacobian committed Apr 9, 2009
1 parent c0ad626 commit de91850
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions django/core/management/validation.py
Expand Up @@ -51,6 +51,8 @@ def get_validation_errors(outfile, app=None):
from PIL import Image from PIL import Image
except ImportError: except ImportError:
e.add(opts, '"%s": To use ImageFields, you need to install the Python Imaging Library. Get it at http://www.pythonware.com/products/pil/ .' % f.name) e.add(opts, '"%s": To use ImageFields, you need to install the Python Imaging Library. Get it at http://www.pythonware.com/products/pil/ .' % f.name)
if isinstance(f, models.BooleanField) and getattr(f, 'null', False):
e.add(opts, '"%s": BooleanFields do not accept null values. Use a NullBooleanField instead.' % f.name)
if f.choices: if f.choices:
if isinstance(f.choices, basestring) or not is_iterable(f.choices): if isinstance(f.choices, basestring) or not is_iterable(f.choices):
e.add(opts, '"%s": "choices" should be iterable (e.g., a tuple or list).' % f.name) e.add(opts, '"%s": "choices" should be iterable (e.g., a tuple or list).' % f.name)
Expand Down
2 changes: 2 additions & 0 deletions tests/modeltests/invalid_models/models.py
Expand Up @@ -14,6 +14,7 @@ class FieldErrors(models.Model):
choices2 = models.CharField(max_length=10, choices=[(1,2,3),(1,2,3)]) choices2 = models.CharField(max_length=10, choices=[(1,2,3),(1,2,3)])
index = models.CharField(max_length=10, db_index='bad') index = models.CharField(max_length=10, db_index='bad')
field_ = models.CharField(max_length=10) field_ = models.CharField(max_length=10)
nullbool = models.BooleanField(null=True)


class Target(models.Model): class Target(models.Model):
tgt_safe = models.CharField(max_length=10) tgt_safe = models.CharField(max_length=10)
Expand Down Expand Up @@ -190,6 +191,7 @@ class UniqueM2M(models.Model):
invalid_models.fielderrors: "choices2": "choices" should be a sequence of two-tuples. invalid_models.fielderrors: "choices2": "choices" should be a sequence of two-tuples.
invalid_models.fielderrors: "index": "db_index" should be either None, True or False. invalid_models.fielderrors: "index": "db_index" should be either None, True or False.
invalid_models.fielderrors: "field_": Field names cannot end with underscores, because this would lead to ambiguous queryset filters. invalid_models.fielderrors: "field_": Field names cannot end with underscores, because this would lead to ambiguous queryset filters.
invalid_models.fielderrors: "nullbool": BooleanFields do not accept null values. Use a NullBooleanField instead.
invalid_models.clash1: Accessor for field 'foreign' clashes with field 'Target.clash1_set'. Add a related_name argument to the definition for 'foreign'. invalid_models.clash1: Accessor for field 'foreign' clashes with field 'Target.clash1_set'. Add a related_name argument to the definition for 'foreign'.
invalid_models.clash1: Accessor for field 'foreign' clashes with related m2m field 'Target.clash1_set'. Add a related_name argument to the definition for 'foreign'. invalid_models.clash1: Accessor for field 'foreign' clashes with related m2m field 'Target.clash1_set'. Add a related_name argument to the definition for 'foreign'.
invalid_models.clash1: Reverse query name for field 'foreign' clashes with field 'Target.clash1'. Add a related_name argument to the definition for 'foreign'. invalid_models.clash1: Reverse query name for field 'foreign' clashes with field 'Target.clash1'. Add a related_name argument to the definition for 'foreign'.
Expand Down
4 changes: 2 additions & 2 deletions tests/regressiontests/serializers_regress/models.py
Expand Up @@ -11,10 +11,10 @@
from django.contrib.localflavor.us.models import USStateField, PhoneNumberField from django.contrib.localflavor.us.models import USStateField, PhoneNumberField


# The following classes are for testing basic data # The following classes are for testing basic data
# marshalling, including NULL values. # marshalling, including NULL values, where allowed.


class BooleanData(models.Model): class BooleanData(models.Model):
data = models.BooleanField(null=True) data = models.BooleanField()


class CharData(models.Model): class CharData(models.Model):
data = models.CharField(max_length=30, null=True) data = models.CharField(max_length=30, null=True)
Expand Down

0 comments on commit de91850

Please sign in to comment.