Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#6361 closed Uncategorized (wontfix)

Models Documentation Default Choice

Reported by: Rupert Owned by: nobody
Component: Documentation Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The documentation for the 'default' field attribute should include information on setting the default when a choices tuple has been used. Something like:

When using a tuple or list of choices enter the index of the choice that you would like to be default. e.g. default=0 would make the first choice the default.

Just though I'd suggest this to improve the already superb documentation.

Change History (4)

comment:1 by Simon Greenhill <dev@…>, 16 years ago

Triage Stage: UnreviewedAccepted

comment:2 by James Bennett, 16 years ago

Resolution: wontfix
Status: newclosed

I'm not sure why there needs to be special documentation for this, as opposed to all the other fields that take a default argument...

comment:3 by anonymous, 13 years ago

Easy pickings: unset
Severity: Normal
Type: Uncategorized

I've only found how to make default choice for my choice field by reading this ticket.

in reply to:  3 comment:4 by anonymous, 13 years ago

Replying to 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:

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.

Note: See TracTickets for help on using tickets.
Back to Top