Browse Source

Fixed #30505 -- Doc'd how changes in the order of Field.choices affect migrations.

Caio Ariede 5 years ago
parent
commit
5248abe9b0
3 changed files with 14 additions and 7 deletions
  1. 1 0
      AUTHORS
  2. 9 6
      docs/ref/models/fields.txt
  3. 4 1
      docs/topics/db/models.txt

+ 1 - 0
AUTHORS

@@ -150,6 +150,7 @@ answer newbie questions, and generally made Django that much better:
     bthomas
     bthomas
     btoll@bestweb.net
     btoll@bestweb.net
     C8E
     C8E
+    Caio Ariede <caio.ariede@gmail.com>
     Calvin Spealman <ironfroggy@gmail.com>
     Calvin Spealman <ironfroggy@gmail.com>
     Cameron Curry
     Cameron Curry
     Cameron Knight (ckknight)
     Cameron Knight (ckknight)

+ 9 - 6
docs/ref/models/fields.txt

@@ -80,7 +80,7 @@ If a field has ``blank=False``, the field will be required.
 
 
 .. attribute:: Field.choices
 .. attribute:: Field.choices
 
 
-An :term:`iterable` consisting itself of iterables of exactly two items (e.g.
+A :term:`sequence` consisting itself of iterables of exactly two items (e.g.
 ``[(A, B), (A, B) ...]``) to use as choices for this field. If choices are
 ``[(A, B), (A, B) ...]``) to use as choices for this field. If choices are
 given, they're enforced by :ref:`model validation <validating-objects>` and the
 given, they're enforced by :ref:`model validation <validating-objects>` and the
 default form widget will be a select box with these choices instead of the
 default form widget will be a select box with these choices instead of the
@@ -155,11 +155,14 @@ method to retrieve the human-readable name for the field's current value. See
 :meth:`~django.db.models.Model.get_FOO_display` in the database API
 :meth:`~django.db.models.Model.get_FOO_display` in the database API
 documentation.
 documentation.
 
 
-Note that choices can be any iterable object -- not necessarily a list or tuple.
-This lets you construct choices dynamically. But if you find yourself hacking
-:attr:`~Field.choices` to be dynamic, you're probably better off using a proper
-database table with a :class:`ForeignKey`. :attr:`~Field.choices` is meant for
-static data that doesn't change much, if ever.
+Note that choices can be any sequence object -- not necessarily a list or
+tuple. This lets you construct choices dynamically. But if you find yourself
+hacking :attr:`~Field.choices` to be dynamic, you're probably better off using
+a proper database table with a :class:`ForeignKey`. :attr:`~Field.choices` is
+meant for static data that doesn't change much, if ever.
+
+.. note::
+    A new migration is created each time the order of ``choices`` changes.
 
 
 Unless :attr:`blank=False<Field.blank>` is set on the field along with a
 Unless :attr:`blank=False<Field.blank>` is set on the field along with a
 :attr:`~Field.default` then a label containing ``"---------"`` will be rendered
 :attr:`~Field.default` then a label containing ``"---------"`` will be rendered

+ 4 - 1
docs/topics/db/models.txt

@@ -154,7 +154,7 @@ ones:
     <Field.blank>`, the field will be required.
     <Field.blank>`, the field will be required.
 
 
 :attr:`~Field.choices`
 :attr:`~Field.choices`
-    An :term:`iterable` of 2-tuples to use as choices for this field. If this
+    A :term:`sequence` of 2-tuples to use as choices for this field. If this
     is given, the default form widget will be a select box instead of the
     is given, the default form widget will be a select box instead of the
     standard text field and will limit choices to the choices given.
     standard text field and will limit choices to the choices given.
 
 
@@ -168,6 +168,9 @@ ones:
             ('GR', 'Graduate'),
             ('GR', 'Graduate'),
         ]
         ]
 
 
+    .. note::
+        A new migration is created each time the order of ``choices`` changes.
+
     The first element in each tuple is the value that will be stored in the
     The first element in each tuple is the value that will be stored in the
     database. The second element is displayed by the field's form widget.
     database. The second element is displayed by the field's form widget.