Re: get_FOO_display() for generic/variable choice fields

2012-01-27 Thread Michael Elkins
On Tue, Jan 24, 2012 at 03:51:27AM -0800, katstevens wrote: Obviously the 'val = obj.get_field_display()' line doesn't work! Is there a generic way of doing this (something like obj.get_display(fieldname) ?) or am I going to have to hard code separate checks for get_country_display() and get_dia

Re: get_FOO_display() for generic/variable choice fields

2012-01-25 Thread katstevens
My Python-expert partner suggested a clever workaround as follows: As I'm already running through the model._meta.fields beforehand to create header row for my .csv file, I can build a dictionary of the choices to refer to later. choices_lookup_dict = {} header_row = [] for field in model._meta.

Re: get_FOO_display() for generic/variable choice fields

2012-01-24 Thread Bill Freeman
Maybe try: val = getattr(obj, 'get_%s_display' % field.name)() On 1/24/12, katstevens wrote: > I have a model ContactDetail with two choice fields, > ContactDetail.dialing_code and ContactDetail.country. These use the > standard tuples ('AU', 'Australia') and so on. > > I know I can use get_cou

get_FOO_display() for generic/variable choice fields

2012-01-24 Thread katstevens
I have a model ContactDetail with two choice fields, ContactDetail.dialing_code and ContactDetail.country. These use the standard tuples ('AU', 'Australia') and so on. I know I can use get_country_display() and get_dialing_code_display() to show the longer values, but is there a more generic versi