Ticket #468: django-choices-accessor.patch
File django-choices-accessor.patch, 1.2 KB (added by , 19 years ago) |
---|
-
django/core/meta/__init__.py
592 592 new_mod.get_latest = curry(function_get_latest, opts, new_class, does_not_exist_exception) 593 593 594 594 for f in opts.fields: 595 if len(f.choices) != 0: 596 # Add an accessor method to get to the human readable value 597 func = curry(method_get_display_value, f) 598 setattr(new_class, 'get_%s_display' % f.name , func) 595 599 if isinstance(f, DateField) or isinstance(f, DateTimeField): 596 600 # Add "get_next_by_thingie" and "get_previous_by_thingie" methods 597 601 # for all DateFields and DateTimeFields that cannot be null. … … 991 995 kwargs['limit'] = 1 992 996 return get_object_func(**kwargs) 993 997 998 # CHOICE-RELATED METHODS ################### 999 1000 def method_get_display_value(field, self): 1001 value = getattr(self, field.name) 1002 for (v, d) in field.choices: 1003 if v==value: 1004 return d 1005 # Couldn't find it in the list 1006 return value 1007 994 1008 # FILE-RELATED METHODS ##################### 995 1009 996 1010 def method_get_file_filename(field, self):