#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 , 17 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 17 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
follow-up: 4 comment:3 by , 14 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.
comment:4 by , 14 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.
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...