Django enumaration problem -



Django enumaration problem -

i seek implement enumartion construction in django such that

class status(): pending = 0 confirmed = 1 denied = 2 status =( (pending,_("salary_status_pending")), (confirmed,_("salary_status_confirmed")), (denied,_("salary_status_denied")), )

and in model utilize like

class mymodel(models.model): status = models.integerfield(null=false, choices=status.status)

it works fine , if want label of enum field in template utilize {{ mymodel.get_status_display }} , writes label _('key..') in enum field instead of number explained in django documents

however, if want label in view.py ? want write code below , should give me label of enum field instead of number

status.confirmed

how can achive ?

thanks

how this?

class mymodel(models.model): pending = 0 confirmed = 1 denied = 2 status = {pending:_("salary_status_pending"), confirmed:..., denied:... } status_choices = [(a,a) in status.items()] status = models.integerfield(null=false, choices=status_choices)

and can access label everywhere using mymodel.status[mymodel.confirmed]

django django-templates django-views enumeration

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -