diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt
index a43163c..d113034 100644
a
|
b
|
If ``True``, the field is allowed to be blank. Default is ``False``.
|
70 | 70 | |
71 | 71 | Note that this is different than :attr:`~Field.null`. :attr:`~Field.null` is |
72 | 72 | purely database-related, whereas :attr:`~Field.blank` is validation-related. If |
73 | | a field has ``blank=True``, validation on Django's admin site will allow entry |
74 | | of an empty value. If a field has ``blank=False``, the field will be required. |
| 73 | a field has ``blank=True``, validation will allow entry of an empty value. If a |
| 74 | field has ``blank=False``, the field will be required. |
75 | 75 | |
76 | 76 | .. _field-choices: |
77 | 77 | |
… |
… |
of an empty value. If a field has ``blank=False``, the field will be required.
|
81 | 81 | .. attribute:: Field.choices |
82 | 82 | |
83 | 83 | An iterable (e.g., a list or tuple) of 2-tuples to use as choices for this |
84 | | field. |
| 84 | field. If this is given, the default form widget will be a select box instead |
| 85 | of the standard text field and will limit choices to the choices given. |
85 | 86 | |
86 | | If this is given, Django's admin will use a select box instead of the standard |
87 | | text field and will limit choices to the choices given. |
88 | | |
89 | | A choices list is an iterable of 2-tuples; the first element in each |
90 | | tuple is the actual value to be stored, and the second element is the |
91 | | human-readable name. For example:: |
| 87 | The first element in each tuple is the actual value to be stored, and the |
| 88 | second element is the human-readable name. For example:: |
92 | 89 | |
93 | 90 | YEAR_IN_SCHOOL_CHOICES = ( |
94 | 91 | ('FR', 'Freshman'), |
… |
… |
callable it will be called every time a new object is created.
|
203 | 200 | |
204 | 201 | .. attribute:: Field.editable |
205 | 202 | |
206 | | If ``False``, the field will not be editable in the admin or via forms |
207 | | automatically generated from the model class. Default is ``True``. |
| 203 | If ``False``, the field will not be displayed in the admin or other |
| 204 | automatically generated forms. Default is ``True``. |
208 | 205 | |
209 | 206 | ``error_messages`` |
210 | 207 | ------------------ |
… |
… |
the `Field types`_ section below.
|
224 | 221 | |
225 | 222 | .. attribute:: Field.help_text |
226 | 223 | |
227 | | Extra "help" text to be displayed under the field on the object's admin form. |
228 | | It's useful for documentation even if your object doesn't have an admin form. |
| 224 | Extra "help" text to be displayed with the form widget. It's useful for |
| 225 | documentation even if your field isn't used on a form. |
229 | 226 | |
230 | | Note that this value is *not* HTML-escaped when it's displayed in the admin |
231 | | interface. This lets you include HTML in :attr:`~Field.help_text` if you so |
| 227 | Note that this value is *not* HTML-escaped in automatically-generated |
| 228 | forms. This lets you include HTML in :attr:`~Field.help_text` if you so |
232 | 229 | desire. For example:: |
233 | 230 | |
234 | 231 | help_text="Please use the following format: <em>YYYY-MM-DD</em>." |
… |
… |
Only one primary key is allowed on an object.
|
259 | 256 | |
260 | 257 | If ``True``, this field must be unique throughout the table. |
261 | 258 | |
262 | | This is enforced at the database level and at the Django admin-form level. If |
| 259 | This is enforced at the database level and by model validation. If |
263 | 260 | you try to save a model with a duplicate value in a :attr:`~Field.unique` |
264 | 261 | field, a :exc:`django.db.IntegrityError` will be raised by the model's |
265 | 262 | :meth:`~django.db.models.Model.save` method. |
… |
… |
For example, if you have a field ``title`` that has
|
279 | 276 | ``unique_for_date="pub_date"``, then Django wouldn't allow the entry of two |
280 | 277 | records with the same ``title`` and ``pub_date``. |
281 | 278 | |
282 | | This is enforced at the Django admin-form level but not at the database level. |
| 279 | This is enforced by model validation but not at the database level. |
283 | 280 | |
284 | 281 | ``unique_for_month`` |
285 | 282 | -------------------- |
… |
… |
otherwise. See :ref:`automatic-primary-key-fields`.
|
337 | 334 | |
338 | 335 | A 64 bit integer, much like an :class:`IntegerField` except that it is |
339 | 336 | guaranteed to fit numbers from -9223372036854775808 to 9223372036854775807. The |
340 | | admin represents this as an ``<input type="text">`` (a single-line input). |
| 337 | default form widget for this field is a |
| 338 | :class:`~django.forms.widgets.TextInput`. |
341 | 339 | |
342 | 340 | |
343 | 341 | ``BooleanField`` |
… |
… |
admin represents this as an ``<input type="text">`` (a single-line input).
|
347 | 345 | |
348 | 346 | A true/false field. |
349 | 347 | |
350 | | The admin represents this as a checkbox. |
| 348 | The default form widget for this field is a |
| 349 | :class:`~django.forms.widgets.CheckboxInput`. |
351 | 350 | |
352 | 351 | If you need to accept :attr:`~Field.null` values then use |
353 | 352 | :class:`NullBooleanField` instead. |
… |
… |
A string field, for small- to large-sized strings.
|
361 | 360 | |
362 | 361 | For large amounts of text, use :class:`~django.db.models.TextField`. |
363 | 362 | |
364 | | The admin represents this as an ``<input type="text">`` (a single-line input). |
| 363 | The default form widget for this field is a |
| 364 | :class:`~django.forms.widgets.TextInput`. |
365 | 365 | |
366 | 366 | :class:`CharField` has one extra required argument: |
367 | 367 | |
… |
… |
optional arguments:
|
414 | 414 | for creation of timestamps. Note that the current date is *always* used; |
415 | 415 | it's not just a default value that you can override. |
416 | 416 | |
417 | | The admin represents this as an ``<input type="text">`` with a JavaScript |
418 | | calendar, and a shortcut for "Today". Includes an additional ``invalid_date`` |
419 | | error message key. |
| 417 | The default form widget for this field is a |
| 418 | :class:`~django.forms.widgets.TextInput`. The admin adds a JavaScript calendar, |
| 419 | and a shortcut for "Today". Includes an additional ``invalid_date`` error |
| 420 | message key. |
420 | 421 | |
421 | 422 | .. note:: |
422 | 423 | As currently implemented, setting ``auto_now`` or ``auto_now_add`` to |
… |
… |
error message key.
|
431 | 432 | A date and time, represented in Python by a ``datetime.datetime`` instance. |
432 | 433 | Takes the same extra arguments as :class:`DateField`. |
433 | 434 | |
434 | | The admin represents this as two ``<input type="text">`` fields, with |
435 | | JavaScript shortcuts. |
| 435 | The default form widget for this field is a single |
| 436 | :class:`~django.forms.widgets.TextInput`. The admin uses two separate |
| 437 | :class:`~django.forms.widgets.TextInput` widgets with JavaScript shortcuts. |
436 | 438 | |
437 | 439 | ``DecimalField`` |
438 | 440 | ---------------- |
… |
… |
decimal places::
|
461 | 463 | |
462 | 464 | models.DecimalField(..., max_digits=19, decimal_places=10) |
463 | 465 | |
464 | | The admin represents this as an ``<input type="text">`` (a single-line input). |
| 466 | The default form widget for this field is a |
| 467 | :class:`~django.forms.widgets.TextInput`. |
465 | 468 | |
466 | 469 | .. note:: |
467 | 470 | |
… |
… |
Also has one optional argument:
|
539 | 542 | Optional. A storage object, which handles the storage and retrieval of your |
540 | 543 | files. See :doc:`/topics/files` for details on how to provide this object. |
541 | 544 | |
542 | | The admin represents this field as an ``<input type="file">`` (a file-upload |
543 | | widget). |
| 545 | The default form widget for this field is a |
| 546 | :class:`~django.forms.widgets.FileInput`. |
544 | 547 | |
545 | 548 | Using a :class:`FileField` or an :class:`ImageField` (see below) in a model |
546 | 549 | takes a few steps: |
… |
… |
can change the maximum length using the :attr:`~CharField.max_length` argument.
|
725 | 728 | |
726 | 729 | A floating-point number represented in Python by a ``float`` instance. |
727 | 730 | |
728 | | The admin represents this as an ``<input type="text">`` (a single-line input). |
| 731 | The default form widget for this field is a |
| 732 | :class:`~django.forms.widgets.TextInput`. |
729 | 733 | |
730 | 734 | .. _floatfield_vs_decimalfield: |
731 | 735 | |
… |
… |
length using the :attr:`~CharField.max_length` argument.
|
776 | 780 | |
777 | 781 | .. class:: IntegerField([**options]) |
778 | 782 | |
779 | | An integer. The admin represents this as an ``<input type="text">`` (a |
780 | | single-line input). |
| 783 | An integer. The default form widget for this field is a |
| 784 | :class:`~django.forms.widgets.TextInput`. |
781 | 785 | |
782 | 786 | ``IPAddressField`` |
783 | 787 | ------------------ |
784 | 788 | |
785 | 789 | .. class:: IPAddressField([**options]) |
786 | 790 | |
787 | | An IP address, in string format (e.g. "192.0.2.30"). The admin represents this |
788 | | as an ``<input type="text">`` (a single-line input). |
| 791 | An IP address, in string format (e.g. "192.0.2.30"). The default form widget |
| 792 | for this field is a :class:`~django.forms.widgets.TextInput`. |
789 | 793 | |
790 | 794 | ``GenericIPAddressField`` |
791 | 795 | ------------------------- |
… |
… |
as an ``<input type="text">`` (a single-line input).
|
795 | 799 | .. versionadded:: 1.4 |
796 | 800 | |
797 | 801 | An IPv4 or IPv6 address, in string format (e.g. ``192.0.2.30`` or |
798 | | ``2a02:42fe::4``). The admin represents this as an ``<input type="text">`` |
799 | | (a single-line input). |
| 802 | ``2a02:42fe::4``). The default form widget for this field is a |
| 803 | :class:`~django.forms.widgets.TextInput`. |
800 | 804 | |
801 | 805 | The IPv6 address normalization follows :rfc:`4291#section-2.2` section 2.2, |
802 | 806 | including using the IPv4 format suggested in paragraph 3 of that section, like |
… |
… |
are converted to lowercase.
|
823 | 827 | .. class:: NullBooleanField([**options]) |
824 | 828 | |
825 | 829 | Like a :class:`BooleanField`, but allows ``NULL`` as one of the options. Use |
826 | | this instead of a :class:`BooleanField` with ``null=True``. The admin represents |
827 | | this as a ``<select>`` box with "Unknown", "Yes" and "No" choices. |
| 830 | this instead of a :class:`BooleanField` with ``null=True``. The default form |
| 831 | widget for this field is a :class:`~django.forms.NullBooleanSelect`. |
828 | 832 | |
829 | 833 | ``PositiveIntegerField`` |
830 | 834 | ------------------------ |
… |
… |
Like an :class:`IntegerField`, but only allows values under a certain
|
875 | 879 | |
876 | 880 | .. class:: TextField([**options]) |
877 | 881 | |
878 | | A large text field. The admin represents this as a ``<textarea>`` (a multi-line |
879 | | input). |
| 882 | A large text field. The default form widget for this field is a |
| 883 | :class:`~django.forms.Textarea`. |
880 | 884 | |
881 | 885 | .. admonition:: MySQL users |
882 | 886 | |
… |
… |
input).
|
893 | 897 | A time, represented in Python by a ``datetime.time`` instance. Accepts the same |
894 | 898 | auto-population options as :class:`DateField`. |
895 | 899 | |
896 | | The admin represents this as an ``<input type="text">`` with some JavaScript |
| 900 | The default form widget for this field is a |
| 901 | :class:`~django.forms.widgets.TextInput`. The admin adds some JavaScript |
897 | 902 | shortcuts. |
898 | 903 | |
899 | 904 | ``URLField`` |
… |
… |
shortcuts.
|
903 | 908 | |
904 | 909 | A :class:`CharField` for a URL. |
905 | 910 | |
906 | | The admin represents this as an ``<input type="text">`` (a single-line input). |
| 911 | The default form widget for this field is a |
| 912 | :class:`~django.forms.widgets.TextInput`. |
907 | 913 | |
908 | 914 | Like all :class:`CharField` subclasses, :class:`URLField` takes the optional |
909 | 915 | :attr:`~CharField.max_length`argument. If you don't specify |
… |
… |
define the details of how the relation works.
|
979 | 985 | .. attribute:: ForeignKey.limit_choices_to |
980 | 986 | |
981 | 987 | A dictionary of lookup arguments and values (see :doc:`/topics/db/queries`) |
982 | | that limit the available admin choices for this object. Use this with |
983 | | functions from the Python ``datetime`` module to limit choices of objects by |
984 | | date. For example:: |
| 988 | that limit the available admin or ModelForm choices for this object. Use |
| 989 | this with functions from the Python ``datetime`` module to limit choices of |
| 990 | objects by date. For example:: |
985 | 991 | |
986 | 992 | limit_choices_to = {'pub_date__lte': datetime.now} |
987 | 993 | |
diff --git a/docs/topics/db/models.txt b/docs/topics/db/models.txt
index ce15dc9..0567f7f 100644
a
|
b
|
determine a few things:
|
108 | 108 | |
109 | 109 | * The database column type (e.g. ``INTEGER``, ``VARCHAR``). |
110 | 110 | |
111 | | * The :doc:`widget </ref/forms/widgets>` to use in Django's admin interface, |
112 | | if you care to use it (e.g. ``<input type="text">``, ``<select>``). |
| 111 | * The default :doc:`widget </ref/forms/widgets>` to use when rendering a form |
| 112 | field (e.g. ``<input type="text">``, ``<select>``). |
113 | 113 | |
114 | 114 | * The minimal validation requirements, used in Django's admin and in |
115 | 115 | automatically-generated forms. |
… |
… |
ones:
|
143 | 143 | Note that this is different than :attr:`~Field.null`. |
144 | 144 | :attr:`~Field.null` is purely database-related, whereas |
145 | 145 | :attr:`~Field.blank` is validation-related. If a field has |
146 | | :attr:`blank=True <Field.blank>`, validation on Django's admin site will |
| 146 | :attr:`blank=True <Field.blank>`, validation will |
147 | 147 | allow entry of an empty value. If a field has :attr:`blank=False |
148 | 148 | <Field.blank>`, the field will be required. |
149 | 149 | |
150 | 150 | :attr:`~Field.choices` |
151 | 151 | An iterable (e.g., a list or tuple) of 2-tuples to use as choices for |
152 | | this field. If this is given, Django's admin will use a select box |
| 152 | this field. If this is given, the default form widget will be a select box |
153 | 153 | instead of the standard text field and will limit choices to the choices |
154 | 154 | given. |
155 | 155 | |
… |
… |
ones:
|
164 | 164 | ) |
165 | 165 | |
166 | 166 | The first element in each tuple is the value that will be stored in the |
167 | | database, the second element will be displayed by the admin interface, |
| 167 | database, the second element will be displayed by the default form widget |
168 | 168 | or in a ModelChoiceField. Given an instance of a model object, the |
169 | 169 | display value for a choices field can be accessed using the |
170 | 170 | ``get_FOO_display`` method. For example:: |
… |
… |
ones:
|
195 | 195 | created. |
196 | 196 | |
197 | 197 | :attr:`~Field.help_text` |
198 | | Extra "help" text to be displayed under the field on the object's admin |
199 | | form. It's useful for documentation even if your object doesn't have an |
200 | | admin form. |
| 198 | Extra "help" text to be displayed with the form widget. It's useful for |
| 199 | documentation even if your field isn't used on a form. |
201 | 200 | |
202 | 201 | :attr:`~Field.primary_key` |
203 | 202 | If ``True``, this field is the primary key for the model. |
… |
… |
It doesn't matter which model has the
|
360 | 359 | :class:`~django.db.models.ManyToManyField`, but you should only put it in one |
361 | 360 | of the models -- not both. |
362 | 361 | |
363 | | Generally, :class:`~django.db.models.ManyToManyField` instances should go in the |
364 | | object that's going to be edited in the admin interface, if you're using |
365 | | Django's admin. In the above example, ``toppings`` is in ``Pizza`` (rather than |
366 | | ``Topping`` having a ``pizzas`` :class:`~django.db.models.ManyToManyField` ) |
367 | | because it's more natural to think about a pizza having toppings than a |
368 | | topping being on multiple pizzas. The way it's set up above, the ``Pizza`` admin |
369 | | form would let users select the toppings. |
| 362 | Generally, :class:`~django.db.models.ManyToManyField` instances should go in |
| 363 | the object that's going to be edited on a form. In the above example, |
| 364 | ``toppings`` is in ``Pizza`` (rather than ``Topping`` having a ``pizzas`` |
| 365 | :class:`~django.db.models.ManyToManyField` ) because it's more natural to think |
| 366 | about a pizza having toppings than a topping being on multiple pizzas. The way |
| 367 | it's set up above, the ``Pizza`` form would let users select the toppings. |
370 | 368 | |
371 | 369 | .. seealso:: |
372 | 370 | |