mirror of
https://github.com/jazzband/django-admin2.git
synced 2026-03-16 22:20:24 +00:00
Added number renderer
This commit is contained in:
parent
5cd153736d
commit
835992b8d0
1 changed files with 18 additions and 0 deletions
|
|
@ -6,8 +6,10 @@ example in the list view.
|
|||
from __future__ import division, absolute_import, unicode_literals
|
||||
|
||||
import os.path
|
||||
from decimal import Decimal
|
||||
from datetime import date, time, datetime
|
||||
|
||||
from django.db import models
|
||||
from django.utils import formats, timezone
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
|
|
@ -63,3 +65,19 @@ def title_renderer(value, field):
|
|||
|
||||
"""
|
||||
return unicode(value).title()
|
||||
|
||||
|
||||
def number_renderer(value, field):
|
||||
"""
|
||||
Format a number.
|
||||
|
||||
:param value: The value to process.
|
||||
:type value: float or long
|
||||
:param field: The model field instance
|
||||
:type field: django.db.models.fields.Field
|
||||
:rtype: unicode
|
||||
|
||||
"""
|
||||
if isinstance(field, models.DecimalField):
|
||||
return formats.number_format(value, field.decimal_places)
|
||||
return formats.number_format(value)
|
||||
|
|
|
|||
Loading…
Reference in a new issue