Hello guys.
I want to show the label of my choices in a template.
This is my model.
class Order(models.Model):
class StatusChoices(models.TextChoices):
pending = "pending", "در حال انتظار"
in_progress = "in progress", "در حال انجام"
completed = "completed", "انجام شده"
processing = "processing", "در حال پردازش"
canceld = "canceld", "لغو شده"
status = models.CharField(
choices=StatusChoices.choices,
default=StatusChoices.pending,
max_length=50,
)
When I try to access the labels on view everything is fine.
Order.StatusChoices.labels # ['در حال انتظار', 'در حال انجام', 'انجام شده', 'در حال پردازش', 'لغو شده']
Order.StatusChoices.canceld.name # 'canceld'
Order.StatusChoices.canceld.value # 'canceld'
Order.StatusChoices.canceld.label # 'لغو شده'
But when I try to show labels on templates it doesn’t work.
{{ orderobj.get_status_display }} // "canceld"
{{ orderobj.status }} // "canceld"
{{ order.status.label }} // EDIT : it dosen't work and i don't know why.
{{ ??? }} // "لغو شده"
And my question is how can I show labels of choices on a template?