mirror of
https://github.com/django/django.git
synced 2025-10-27 07:36:08 +00:00
newforms: Implemented NullBooleanField and NullBooleanSelect
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4411 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -4,7 +4,7 @@ Field classes
|
||||
|
||||
from django.utils.translation import gettext
|
||||
from util import ErrorList, ValidationError, smart_unicode
|
||||
from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, CheckboxInput, Select, SelectMultiple
|
||||
from widgets import TextInput, PasswordInput, HiddenInput, MultipleHiddenInput, CheckboxInput, Select, NullBooleanSelect, SelectMultiple
|
||||
import datetime
|
||||
import re
|
||||
import time
|
||||
@@ -15,7 +15,7 @@ __all__ = (
|
||||
'DEFAULT_TIME_INPUT_FORMATS', 'TimeField',
|
||||
'DEFAULT_DATETIME_INPUT_FORMATS', 'DateTimeField',
|
||||
'RegexField', 'EmailField', 'URLField', 'BooleanField',
|
||||
'ChoiceField', 'MultipleChoiceField',
|
||||
'ChoiceField', 'NullBooleanField', 'MultipleChoiceField',
|
||||
'ComboField', 'MultiValueField',
|
||||
'SplitDateTimeField',
|
||||
)
|
||||
@@ -317,6 +317,16 @@ class BooleanField(Field):
|
||||
super(BooleanField, self).clean(value)
|
||||
return bool(value)
|
||||
|
||||
class NullBooleanField(BooleanField):
|
||||
"""
|
||||
A field whose valid values are None, True and False. Invalid values are
|
||||
cleaned to None.
|
||||
"""
|
||||
widget = NullBooleanSelect
|
||||
|
||||
def clean(self, value):
|
||||
return {True: True, False: False}.get(value, None)
|
||||
|
||||
class ChoiceField(Field):
|
||||
def __init__(self, choices=(), required=True, widget=Select, label=None, initial=None):
|
||||
if isinstance(widget, type):
|
||||
|
||||
Reference in New Issue
Block a user