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