python - How do I retrieve key from value in django choices field? -


the sample code below:

refund_status = (     ('s', 'success'),     ('f', 'fail') ) refund_status = models.charfield(max_length=3, choices=refund_status) 

i know in model can retrieve success method get_refund_status_display() method. however, if want reversely like: have 'success' want find abbreviated form 's'. how can in django or python?

i write that:

next(iter([x[0] x in refund_status if 'success' in x]), none) 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -