| 475 | |
| 476 | |
| 477 | def display_for_value(value, empty_value_display, boolean=False): |
| 478 | from django.contrib.admin.templatetags.admin_list import _boolean_icon |
| 479 | |
| 480 | if boolean: |
| 481 | return _boolean_icon(value) |
| 482 | if isinstance(value, str) and not isinstance(value, SafeString): |
| 483 | value = value.strip() |
| 484 | if value in EMPTY_VALUES: |
| 485 | return empty_value_display |
| 486 | elif isinstance(value, bool): |
| 487 | return str(value) |
| 488 | elif isinstance(value, datetime.datetime): |
| 489 | return formats.localize(timezone.template_localtime(value)) |
| 490 | elif isinstance(value, (datetime.date, datetime.time)): |
| 491 | return formats.localize(value) |
| 492 | elif isinstance(value, (int, decimal.Decimal, float)): |
| 493 | return formats.number_format(value) |
| 494 | elif isinstance(value, (list, tuple)): |
| 495 | return ", ".join(str(v) for v in value) |
| 496 | else: |
| 497 | return str(value) |
| 498 | |
| 499 | |
| 500 | class NotRelationField(Exception): |