Skip to content

Commit eaa716a

Browse files
committed
Fixed django#19639 - Updated contributing to reflect model choices best practices.
Thanks charettes.
1 parent e2252bf commit eaa716a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

docs/internals/contributing/writing-code/coding-style.txt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,17 @@ Model style
136136
* ``def get_absolute_url()``
137137
* Any custom methods
138138

139-
* If ``choices`` is defined for a given model field, define the choices as
140-
a tuple of tuples, with an all-uppercase name, either near the top of
141-
the model module or just above the model class. Example::
142-
143-
DIRECTION_CHOICES = (
144-
('U', 'Up'),
145-
('D', 'Down'),
146-
)
139+
* If ``choices`` is defined for a given model field, define each choice as
140+
a tuple of tuples, with an all-uppercase name as a class attribute on the
141+
model. Example::
142+
143+
class MyModel(models.Model):
144+
DIRECTION_UP = 'U'
145+
DIRECTION_DOWN = 'D'
146+
DIRECTION_CHOICES = (
147+
(DIRECTION_UP, 'Up'),
148+
(DIRECTION_DOWN, 'Down'),
149+
)
147150

148151
Use of ``django.conf.settings``
149152
-------------------------------

0 commit comments

Comments
 (0)