From d571894fc09b34b8b43cb8f1790c743a47679851 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Thu, 24 Jan 2013 06:53:32 -0500 Subject: [PATCH] [1.5.x] Fixed #19639 - Updated contributing to reflect model choices best practices. Thanks charettes. Backport of eaa716a413 from master --- .../contributing/writing-code/coding-style.txt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/docs/internals/contributing/writing-code/coding-style.txt b/docs/internals/contributing/writing-code/coding-style.txt index 0d84cdac9a4..21146600b40 100644 --- a/docs/internals/contributing/writing-code/coding-style.txt +++ b/docs/internals/contributing/writing-code/coding-style.txt @@ -136,14 +136,17 @@ Model style * ``def get_absolute_url()`` * Any custom methods -* If ``choices`` is defined for a given model field, define the choices as - a tuple of tuples, with an all-uppercase name, either near the top of - the model module or just above the model class. Example:: +* If ``choices`` is defined for a given model field, define each choice as + a tuple of tuples, with an all-uppercase name as a class attribute on the + model. Example:: - DIRECTION_CHOICES = ( - ('U', 'Up'), - ('D', 'Down'), - ) + class MyModel(models.Model): + DIRECTION_UP = 'U' + DIRECTION_DOWN = 'D' + DIRECTION_CHOICES = ( + (DIRECTION_UP, 'Up'), + (DIRECTION_DOWN, 'Down'), + ) Use of ``django.conf.settings`` -------------------------------