Here I my custom model field I created it
class CurrencyAmountField(models.DecimalField):
INTEGER_PLACES = 5
DECIMAL_PLACES = 5
DECIMAL_PLACES_FOR_USER = 2
MAX_DIGITS = INTEGER_PLACES + DECIMAL_PLACES
MAX_VALUE = Decimal('99999.99999')
MIN_VALUE = Decimal('-99999.99999')
def __init__(self, verbose_name=None, name=None, max_digits=MAX_DIGITS,
decimal_places=DECIMAL_PLACES, **kwargs):
super().__init__(verbose_name=verbose_name, name=name, max_digits=max_digits,
decimal_places=decimal_places, **kwargs)
How can I show the numbers in a comma-separated mode in Django admin forms? Should I override some method here on this custom model field or there is another to do that?
Should be:
Update:
Tried to use intcomma like this:
{% extends "admin/change_form.html" %}
{% load humanize %}
{% block field_sets %}
{% for fieldset in adminform %}
<fieldset class="module aligned {{ fieldset.classes }}">
{% if fieldset.name %}<h2>{{ fieldset.name }}</h2>{% endif %}
{% if fieldset.description %}
<div class="description">{{ fieldset.description|safe }}</div>
{% endif %}
{% for line in fieldset %}
<div class="form-row{% if line.fields|length_is:'1' and line.errors %} errors{% endif %}{% if not line.has_visible_field %} hidden{% endif %}{% for field in line %}{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% endfor %}">
{% if line.fields|length_is:'1' %}{{ line.errors }}{% endif %}
{% for field in line %}
<div{% if not line.fields|length_is:'1' %} class="fieldBox{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}{% if field.field.is_hidden %} hidden{% endif %}"{% elif field.is_checkbox %} class="checkbox-row"{% endif %}>
{% if not line.fields|length_is:'1' and not field.is_readonly %}{{ field.errors }}{% endif %}
{% if field.is_checkbox %}
{{ field.field }}{{ field.label_tag }}
{% else %}
{{ field.label_tag }}
{% if field.is_readonly %}
<div class="readonly">{{ field.contents }}</div>
{% else %}
{{ field.field|intcomma }}
{% endif %}
{% endif %}
{% if field.field.help_text %}
<div class="help">{{ field.field.help_text|safe }}</div>
{% endif %}
</div>
{% endfor %}
</div>
{% endfor %}
</fieldset>
{% endfor %}
{% endblock %}
As you can see I added intcomma like this: {{ field.field|intcomma }}
But I get HTML codes on my admin page instead of the forms and labels.
What's wrong here?
My priority is to use the first method and 'CurrencyAmountField'.