Opened 15 years ago

Closed 15 years ago

#12331 closed (worksforme)

get_display shows choices key, not value if field name contains underscore symbol

Reported by: anonymous Owned by: nobody
Component: Template system Version: dev
Severity: Keywords: choices, get_display
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

CURRENCY_CHOICES = (
	(u"USD", u"$"),
	(u"EUR", u"€"),
)
buyer_currency = models.CharField(u"Price", choices = CURRENCY_CHOICES, max_length=3, default='USD')

template:
{{user.userprofile.get_buyer_currency_display|safe}} shows "USD"
after rebuilding model with no underscore it works as it should:
{{user.userprofile.get_buyercurrency_display|safe}} shows "$"

Change History (1)

comment:1 by Karen Tracey, 15 years ago

Resolution: worksforme
Status: newclosed

I cannot recreate this. Using this model:

from django.contrib.auth.models import User
class CTest(models.Model):
    CURRENCY_CHOICES = (
        (u"USD", u"$"),
        (u"EUR", u"€"),
    )
    buyer_currency = models.CharField(u"Price", choices = CURRENCY_CHOICES, max_length=3, default='USD')
    buyercurrency = models.CharField(u"Price2", choices = CURRENCY_CHOICES, max_length=3, default='EUR')
    user = models.ForeignKey(User)
    def __unicode__(self):
        return u'Profile for %s: buyer_currency = %s, buyercurrency = %s' % \
                 (self.user.username, self.buyer_currency, self.buyercurrency)

specified as AUTH_PROFILE_MODULE in settings.py, with a view that passes a RequestContext to a template that includes:

User is {{ user }} <br/>
{{ user.get_profile }} <br/>
get_buyer_currency_display returns: {{user.get_profile.get_buyer_currency_display|safe}} <br/>
get_buyercurrency_display returns: {{user.get_profile.get_buyercurrency_display|safe}} <br/>

The displayed page when logged in with a user that has a profile shows:

User is kmt
Profile for kmt: buyer_currency = USD, buyercurrency = EUR
get_buyer_currency_display returns: $
get_buyercurrency_display returns: € 
Note: See TracTickets for help on using tickets.
Back to Top