Fixed get_field_display method for None value.
This commit is contained in:
parent
009d6c1c52
commit
cbfe2ee9bd
1 changed files with 9 additions and 8 deletions
|
@ -111,14 +111,15 @@ class MultiSelectField(models.CharField):
|
|||
fieldname = name
|
||||
choicedict = dict(self.choices)
|
||||
display = []
|
||||
for value in getattr(obj, fieldname):
|
||||
item_display = choicedict.get(value, None)
|
||||
if item_display is None:
|
||||
try:
|
||||
item_display = choicedict.get(int(value), value)
|
||||
except (ValueError, TypeError):
|
||||
item_display = value
|
||||
display.append(string_type(item_display))
|
||||
if getattr(obj, fieldname):
|
||||
for value in getattr(obj, fieldname):
|
||||
item_display = choicedict.get(value, None)
|
||||
if item_display is None:
|
||||
try:
|
||||
item_display = choicedict.get(int(value), value)
|
||||
except (ValueError, TypeError):
|
||||
item_display = value
|
||||
display.append(string_type(item_display))
|
||||
return ", ".join(display)
|
||||
setattr(cls, 'get_%s_display' % self.name, get_display)
|
||||
|
||||
|
|
Loading…
Reference in a new issue