On Mon, 2008-02-04 at 11:22 -0800, [EMAIL PROTECTED] wrote:
> I'm talking about this kind of choices field
> http://www.djangoproject.com/documentation/model-api/#choices
> 
> e.g.
> class Foo(models.Model):
>     GENDER_CHOICES = (
>         ('M', 'Male'),
>         ('F', 'Female'),
>     )
>     gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
> 
> Is there a reason to not mirror the actual value stored with the human
> readable one? Are you buying much by having a single character rather
> than around 20 or 30?

It depends on how the data will be used. If you're extracting this data
via some other process, a column of "m" and "f" values is easier to scan
than the variable length "male" / "female" fields. Sometimes it's handy
to use an integer as the stored choice value, rather than a string. This
allows you to specify some kind of ordering on the choices (e.g. a
preference value from 0 to 5) which can be easily used in searching and
sorting later.

For this particular example, though, there's not really any huge
difference. It's an example that shows you don't have to use the same
values in both places (if we used the same value, some people wouldn't
make the obvious jump and then post queries asking why the example
didn't show different values).

So there's no one true answer here (except "it depends on
circumstances").

Regards,
Malcolm

-- 
Why be difficult when, with a little bit of effort, you could be
impossible. 
http://www.pointy-stick.com/blog/


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

Reply via email to