Answer the question
In order to leave comments, you need to log in
How to select all choices in the model to pass them to the template?
There is a simple model that has a field for selecting the transaction status:
class ModelDeal(models.Model):
STATUS_CHOISES = (
('ok', 'Выполнена'),
('new', 'Новая заявка'),
('cancel', 'Отменена'),
('error', 'Ошибка'),
('timesup', 'Время вышло'),
)
deal_status = models.CharField('Статус', max_length=50, choices=STATUS_CHOISES, default='new')
Answer the question
In order to leave comments, you need to log in
There are two options:
# Вызвать напрямую
var = ModelDeal.STATUS_CHOISES
# Создать метод класса
@classmethod
def return_choises(cls):
return cls.STATUS_CHOISES
***
var = ModelDeal.return_choises()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question