On 1/9/07, Chris Brand <[EMAIL PROTECTED]> wrote:
> In the admin, it displays the current value nicely (the second column), but
> on my page, it displays the actual value from the database (the first
> column) instead. I'd like to display the value used by the admin form, but
> can't figure where to start.

Each instance of your model will have a special method name
'get_foo_display', where 'foo' is the name of the field with the
choices. For example:

BLOG_TYPES = (
  (1, 'Staff')
  (2, 'User')
)

class Blog(models.Model):
    title = models.CharField(maxlength=200)
    kind = models.IntegerField(choices=BLOG_TYPES)

Then you could do:

>>> b = Blog.objects.create(title='Official staff blog', kind=1)
>>> b.kind
1
>>> b.get_kind_display()
'Staff'

Full documentation is here:
http://www.djangoproject.com/documentation/db_api/#get-foo-display

-- 
"May the forces of evil become confused on the way to your house."
  -- George Carlin

--~--~---------~--~----~------------~-------~--~----~
 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