In the webpage this renders as
Status: i
How do i display the long name "Initiated" in the django template?
In my Template
<p>Status: {{ transaction.status }}</p>
models.py
class Transaction(models.Model):
creator = models.SlugField()
amount = models.DecimalField(max_digits= 999,decimal_places =2,null= True,default=0)
accepted_by = models.SlugField()
oferto_slug = models.SlugField()
STATUSES = (
('i', 'Initiated'),
('a', 'Accepted'),
('d', 'Delivered'),
('c', 'Cancelled'),
)
status = models.CharField(choices=STATUSES, default='i',max_length=10)
views.py
def __init__():
self.state = 'i'
In your template, try this instead:
<p>Status: {{ transaction.get_status_display }}</p>
You simply add the qualified field name between get_ and _display. (There is no need for parentheses after the method name in the template.) This will give you access to the human readable form.
See the docs here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With