2

i have tuple

PRICES_DATES_SD_PRICES_CHOICES = (('SD-A', 'Option SD-A'), ('SD-B', 'Option SD-B'), ('SD-C', 'Option SD-C'))

and my model like this:

class PackagePricesAndDates(models.Model):`
      prices_SD = models.CharField(max_length=255, choices=PRICES_DATES_SD_PRICES_CHOICES)`

in the template when i loop in object_list :

{% for pricedate in object_list %}
<tr>
                    <td colspan=3 style="border-top:rgba(255, 255, 255, 0.7) solid 1px;padding-top:17px;">
                        <table class="sub">
                        <tr>
                            <td style="width:50%">Prices SD</td>
                            <td>""""{{ pricedate.prices_SD }}</td>
                        </tr>
                        <tr>
                            <td>Prices HD</td>
                            <td>""""{{ pricedate.prices_HD }}</td>
                        </tr>
                        </table>
                    </td>
                </tr>

the value of pricedate.prices_SD display the key not the value of tuple (the first value not the second) how can i get the second value ?

Abdeljalil
  • 23
  • 7

2 Answers2

2

Try {{ pricedate.get_prices_SD_display }}

Syntax : get_FIELDNAME_display()

Reference : https://docs.djangoproject.com/en/dev/ref/models/instances/#django.db.models.Model.get_FOO_display

Umair Mohammad
  • 4,489
  • 2
  • 20
  • 34
0

It's because this line of code is returning key, not the value.

{{ pricedate.prices_SD }}

There's a method called get_FOO_display() in Django which you can use. Try this instead..

{{pricedate.get_prices_SD_display}}
Sulove Bista
  • 118
  • 8