[Answered ]-Accessing dictionary in django template engine

2👍

Use a choices argument for your credit_facility field and the (automagic) get_credit_facility_display() method to get the associated label:

class Customer(models.Model):
    CREDIT_FACILITY_CHOICES = (
      (1, "Yes"),
      (2, "No"),
      (3, "Not sure")
      )
    credit_facility = models.IntegerField(
       "credit facility", 
       choices = CREDIT_FACILITY_CHOICES
       )

then:

>>> c = Customer(1)
>>> c.get_credit_facility_display()
"Yes"

Full documentation here : https://docs.djangoproject.com/en/1.10/ref/models/fields/#choices

Leave a comment