#6361: Models Documentation Default Choice
-----------------------------------------+-------------------------------
               Reporter:  Rupert         |          Owner:  nobody
                   Type:  Uncategorized  |         Status:  closed
              Milestone:                 |      Component:  Documentation
                Version:  SVN            |       Severity:  Normal
             Resolution:  wontfix        |       Keywords:
           Triage Stage:  Accepted       |      Has patch:  0
    Needs documentation:  0              |    Needs tests:  0
Patch needs improvement:  0              |  Easy pickings:  0
-----------------------------------------+-------------------------------

Comment (by anonymous):

 Replying to [comment:3 anonymous]:
 > I've only found how to make default choice for my choice field by
 reading this ticket.

 Hmm, you might want to know then that the ticket description is wrong.
 Setting a default of 0 gives that as the default: 0. Not the value
 associated with the 1st element in the choices list. For example with this
 model:

 {{{
 #!python
 class Thingy(models.Model):
     ttype = models.CharField(max_length=20, choices=(('abc', 'ABC!'),
 ('123', '123!')), default=0)
 }}}

 you get a Thingy with ttype value 0, not 'abc', when you create a Thingy
 and don't specify ttype:

 {{{
 >>> from ttt.models import Thingy
 >>> newt = Thingy.objects.create()
 >>> newt.ttype
 0
 >>>
 }}}

 There is nothing special about specifying the default value for a field
 that has choices specified. You need to specify just that: the default
 value you want the field to have, just as you do for fields without
 choices. choices are orthoganal and used for form presentation purposes
 only; there is no consideration of the choices value when the default
 value is recorded or used.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/6361#comment:4>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to