Opened 15 years ago

Closed 15 years ago

Last modified 12 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


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 Changed 15 years ago by Simon Greenhill <dev@…>

Triage Stage: UnreviewedAccepted

comment:2 Changed 15 years ago by James Bennett

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 Changed 12 years ago by anonymous

Easy pickings: unset
Severity: Normal
Type: Uncategorized

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

comment:4 in reply to:  3 Changed 12 years ago by anonymous

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

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