| 862 | Field types |
| 863 | ----------- |
| 864 | |
| 865 | ``BooleanField`` |
| 866 | ~~~~~~~~~~~~~~~~ |
| 867 | |
| 868 | Default widget: ``CheckboxInput`` |
| 869 | |
| 870 | Cleans to a Python ``True`` or ``False`` value. |
| 871 | |
| 872 | ``CharField`` |
| 873 | ~~~~~~~~~~~~~ |
| 874 | |
| 875 | Default widget: ``TextInput`` |
| 876 | |
| 877 | Has two optional arguments for validation, ``max_length`` and ``min_length`` |
| 878 | which if provided, ensure that the string is at most or at least the given |
| 879 | length. |
| 880 | |
| 881 | ``ChoiceField`` |
| 882 | ~~~~~~~~~~~~~~~ |
| 883 | |
| 884 | Default widget: ``Select`` |
| 885 | |
| 886 | Cleans to a one of the values given in ``choices``. |
| 887 | |
| 888 | Takes one extra argument, ``choices``, which is an iterable (e.g., a list or |
| 889 | tuple) of 2-tuples to use as choices for this field. |
| 890 | |
| 891 | ``ComboField`` |
| 892 | ~~~~~~~~~~~~~~ |
| 893 | |
| 894 | Default widget: ``TextInput`` |
| 895 | |
| 896 | Takes one extra argument, ``fields``, which is a list of fields which are used |
| 897 | (in order) to clean the provided value. |
| 898 | |
| 899 | ``DateField`` |
| 900 | ~~~~~~~~~~~~~ |
| 901 | |
| 902 | Default widget: ``TextInput`` |
| 903 | |
| 904 | Cleans to a ``datetime.date`` object. Accepts ``datetime.datetime``, |
| 905 | ``datetime.date`` and strings. |
| 906 | |
| 907 | Takes one optional argument, ``input_formats``, which is a list of formats used |
| 908 | to attempt to convert a string to a valid ``datetime.date`` object. |
| 909 | |
| 910 | If no ``input_formats`` argument is provided, the default input formats are:: |
| 911 | |
| 912 | '%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', # '2006-10-25', '10/25/2006', '10/25/06' |
| 913 | '%b %d %Y', '%b %d, %Y', # 'Oct 25 2006', 'Oct 25, 2006' |
| 914 | '%d %b %Y', '%d %b, %Y', # '25 Oct 2006', '25 Oct, 2006' |
| 915 | '%B %d %Y', '%B %d, %Y', # 'October 25 2006', 'October 25, 2006' |
| 916 | '%d %B %Y', '%d %B, %Y', # '25 October 2006', '25 October, 2006' |
| 917 | |
| 918 | ``DateTimeField`` |
| 919 | ~~~~~~~~~~~~~~~~~ |
| 920 | |
| 921 | Default widget: ``TextInput`` |
| 922 | |
| 923 | Cleans to a ``datetime.datetime`` object. Accepts ``datetime.datetime``, |
| 924 | ``datetime.date`` and strings. |
| 925 | |
| 926 | Takes one optional argument, ``input_formats``, which is a list of formats used |
| 927 | to attempt to convert a string to a valid ``datetime.datetime`` object. |
| 928 | |
| 929 | If no ``input_formats`` argument is provided, the default input formats are:: |
| 930 | |
| 931 | '%Y-%m-%d %H:%M:%S', # '2006-10-25 14:30:59' |
| 932 | '%Y-%m-%d %H:%M', # '2006-10-25 14:30' |
| 933 | '%Y-%m-%d', # '2006-10-25' |
| 934 | '%m/%d/%Y %H:%M:%S', # '10/25/2006 14:30:59' |
| 935 | '%m/%d/%Y %H:%M', # '10/25/2006 14:30' |
| 936 | '%m/%d/%Y', # '10/25/2006' |
| 937 | '%m/%d/%y %H:%M:%S', # '10/25/06 14:30:59' |
| 938 | '%m/%d/%y %H:%M', # '10/25/06 14:30' |
| 939 | '%m/%d/%y', # '10/25/06' |
| 940 | |
| 941 | ``EmailField`` |
| 942 | ~~~~~~~~~~~~~~ |
| 943 | |
| 944 | Default widget: ``TextInput`` |
| 945 | |
| 946 | Based on a ``RegexField``, checks that the provided string looks like a |
| 947 | valid email when cleaning. |
| 948 | |
| 949 | Has two optional arguments for validation, ``max_length`` and ``min_length`` |
| 950 | which if provided, ensure that the string is at most or at least the given |
| 951 | length. |
| 952 | |
| 953 | ``Field`` |
| 954 | ~~~~~~~~~~~~~~ |
| 955 | |
| 956 | Default widget: ``TextInput`` |
| 957 | |
| 958 | This is the base ``Field`` type usually not used directly. |
| 959 | |
| 960 | ``IntegerField`` |
| 961 | ~~~~~~~~~~~~~~~~ |
| 962 | |
| 963 | Default widget: ``TextInput`` |
| 964 | |
| 965 | Cleans to an Python ``int`` (or ``long``) object. |
| 966 | |
| 967 | ``MultiValueField`` |
| 968 | ~~~~~~~~~~~~~~~~~~~ |
| 969 | |
| 970 | Composed of multiple ``Field``s, this is a base ``Field`` type not used |
| 971 | directly. |
| 972 | |
| 973 | Its ``clean()`` method takes a "decompressed" list of values. Each value in |
| 974 | this list is cleaned by the corresponding field -- the first value is |
| 975 | cleaned by the first field, the second value is cleaned by the second |
| 976 | field, etc. Once all fields are cleaned, the list of clean values is |
| 977 | "compressed" into a single value using a ``compress()`` method defined |
| 978 | in sub-classes. |
| 979 | |
| 980 | You'll probably want to use this with ``MultiWidget``. |
| 981 | |
| 982 | ``MultipleChoiceField`` |
| 983 | ~~~~~~~~~~~~~~~~~~~~~~~ |
| 984 | |
| 985 | Default widget: ``SelectMultiple`` |
| 986 | |
| 987 | Cleans to a list of values given in ``choices`` (Takes a python ``list`` or |
| 988 | ``tuple``). |
| 989 | |
| 990 | Takes one extra argument, ``choices``, which is an iterable (e.g., a list or |
| 991 | tuple) of 2-tuples to use as choices for this field. |
| 992 | |
| 993 | ``NullBooleanField`` |
| 994 | ~~~~~~~~~~~~~~~~~~~~ |
| 995 | |
| 996 | Default widget: ``NullBooleanSelect`` |
| 997 | |
| 998 | Cleans to a Python ``True``, ``False`` or ``None`` value. Invalid values are |
| 999 | cleaned to ``None``. |
| 1000 | |
| 1001 | ``NullBooleanField`` |
| 1002 | ~~~~~~~~~~~~~~~~~~~~ |
| 1003 | |
| 1004 | Default widget: ``TextInput`` |
| 1005 | |
| 1006 | Validates a string using a regular expression. |
| 1007 | |
| 1008 | Takes the following arguments, used during cleaning: |
| 1009 | |
| 1010 | ====================== =================================================== |
| 1011 | Argument Description |
| 1012 | ====================== =================================================== |
| 1013 | ``regex`` Either a string or a compiled regular expression |
| 1014 | object used for validation. Required argument. |
| 1015 | ``max_length`` Optional value to ensure the string has at most |
| 1016 | this many characters. |
| 1017 | ``min_length`` Optional value to ensure the string has at least |
| 1018 | this many characters. |
| 1019 | ``error_message`` Optional error message to return for failed |
| 1020 | validation. If no message is provided, a generic |
| 1021 | error message will be used. |
| 1022 | ====================== =================================================== |
| 1023 | |
| 1024 | ``SplitDateTimeField`` |
| 1025 | ~~~~~~~~~~~~~~~~~~~~~~ |
| 1026 | |
| 1027 | A ``MultiValueField`` which combines a ``DateField`` and a ``TimeField`` to a |
| 1028 | single ``datetime.datetime`` object. |
| 1029 | |
| 1030 | ``TimeField`` |
| 1031 | ~~~~~~~~~~~~~ |
| 1032 | |
| 1033 | Default widget: ``TextInput`` |
| 1034 | |
| 1035 | Cleans to a ``datetime.time`` object. Accepts ``datetime.time`` and string |
| 1036 | objects. |
| 1037 | |
| 1038 | Takes one optional argument, ``input_formats``, which is a list of formats used |
| 1039 | to attempt to convert a string to a valid ``datetime.date`` object. |
| 1040 | |
| 1041 | If no ``input_formats`` argument is provided, the default input formats are:: |
| 1042 | |
| 1043 | '%H:%M:%S', # '14:30:59' |
| 1044 | '%H:%M', # '14:30' |
| 1045 | |
| 1046 | ``URLField`` |
| 1047 | ~~~~~~~~~~~~~~ |
| 1048 | |
| 1049 | Default widget: ``TextInput`` |
| 1050 | |
| 1051 | Based on a ``RegexField``, checks that the provided string is a valid URL |
| 1052 | when cleaning. |
| 1053 | |
| 1054 | Takes the following arguments: |
| 1055 | |
| 1056 | ======================== ================================================= |
| 1057 | Argument Description |
| 1058 | ======================== ================================================= |
| 1059 | ``max_length`` Optional value to ensure the string has at most |
| 1060 | this many characters. |
| 1061 | ``min_length`` Optional value to ensure the string has at least |
| 1062 | this many characters. |
| 1063 | ``verify_exists`` If ``True``, the URL given will be checked for |
| 1064 | existence (i.e., the URL actually loads and |
| 1065 | doesn't give a 404 response). Defaults to |
| 1066 | ``False``. |
| 1067 | ``validator_user_agent`` Optional string used as the user-agent used when |
| 1068 | checking for a URL's existence. Defaults to |
| 1069 | ``settings.URL_VALIDATOR_USER_AGENT`` or if not |
| 1070 | found there, |
| 1071 | ``'Django (http://www.djangoproject.com/)'``. |
| 1072 | ======================== ================================================= |
| 1073 | |