Name for "choices accessor" methods

31 views
Skip to first unread message

Adrian Holovaty

unread,
Sep 18, 2005, 11:30:31 PM9/18/05
to django-d...@googlegroups.com
Ticket #468 -- http://code.djangoproject.com/ticket/468 -- is a great
idea. It suggests that any model field with a "choices" parameter
should generate a get_fieldname_display() method. Here's an example:

"""
STATE_CHOICES = (
('IL', 'Illinois'),
('KS', 'Kansas'),
)

class Location(meta.Model):
state = meta.CharField(maxlength=2, choices=STATE_CHOICES)

>>> loc = Location("IL")
>>> loc.get_state_display()
"Illinois"
"""

This would be a great addition, but I feel like the function name
("get_state_display") could be improved. What could we use instead of
"display"?

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org

Robert Wittams

unread,
Sep 19, 2005, 5:51:03 AM9/19/05
to django-d...@googlegroups.com
Yeah, I thought it was a sucky name when I wrote it ;-)

Sune Kirkeby

unread,
Sep 19, 2005, 7:27:03 AM9/19/05
to django-d...@googlegroups.com
On 9/19/05, Adrian Holovaty <holo...@gmail.com> wrote:
> This would be a great addition, but I feel like the function name
> ("get_state_display") could be improved. What could we use instead of
> "display"?

How about a pair of "get_state_key" / "get_state_value"? That would
go nicely with it looking like a list-i-fied dict...

I also like "render_state" or one could go with "get_state_..." and make
the actual postfix a field parameter ("choices_noun"?).

/s

Jason Huggins

unread,
Sep 19, 2005, 8:52:14 PM9/19/05
to Django developers

Adrian Holovaty wrote:
> >>> loc.get_state_display()

>
> This would be a great addition, but I feel like the function name
> ("get_state_display") could be improved. What could we use instead of
> "display"?


How about
>>> loc.get_state_description()
or
>> loc.get_state_descr()

In the apps I write, my "two column" lookup tables use the column names
of "code" and "description"... I don't see why it couldn't apply in
this case, too.

-Jason

Jason Davies

unread,
Sep 23, 2005, 8:38:48 PM9/23/05
to Django developers
Adrian Holovaty wrote:

> This would be a great addition, but I feel like the function name
> ("get_state_display") could be improved. What could we use instead of
> "display"?

Perhaps get_fieldname_alt() would be nice?

Adrian Holovaty

unread,
Sep 25, 2005, 5:37:47 PM9/25/05
to django-d...@googlegroups.com
On 9/18/05, Adrian Holovaty <holo...@gmail.com> wrote:
> Ticket #468 -- http://code.djangoproject.com/ticket/468 -- is a great
> idea. It suggests that any model field with a "choices" parameter
> should generate a get_fieldname_display() method.

I've checked in this change. I ended up using get_fieldname_display().
Reply all
Reply to author
Forward
0 new messages