Django

Code

Changeset 1570

Show
Ignore:
Timestamp:
12/08/05 19:53:30 (3 years ago)
Author:
adrian
Message:

Fixed #972 -- Improved docs for 'choices' model field option. Thanks, radek

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/model-api.txt

    r1426 r1570  
    104104    The first element in each tuple is the actual value to be stored. The 
    105105    second element is the human-readable name for the option. 
     106 
     107    Define the choices list **outside** of your model class, not inside it. 
     108    For example, this is not valid:: 
     109 
     110        class Foo(meta.Model): 
     111            GENDER_CHOICES = ( 
     112                ('M', 'Male'), 
     113                ('F', 'Female'), 
     114            ) 
     115            gender = meta.CharField(maxlength=1, choices=GENDER_CHOICES) 
     116 
     117    But this is valid:: 
     118 
     119        GENDER_CHOICES = ( 
     120            ('M', 'Male'), 
     121            ('F', 'Female'), 
     122        ) 
     123        class Foo(meta.Model): 
     124            gender = meta.CharField(maxlength=1, choices=GENDER_CHOICES) 
    106125 
    107126``core``