﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35177	Admin.display decorator functions do not output correct-format for 'modern' Python string-formatting	Stephen Skett	nobody	"I am trying to write an admin display function (using the [https://github.com/django/django/blob/main/django/contrib/admin/decorators.py admin.display decorator]) to output the values of a float-field to 3 decimal places.

Seemed like this should be pretty simple, and indeed it is, **IF** you use 'old-style' Python format-strings, e.g.
{{{
class ModelFoo_Admin(admin.ModelAdmin):
    @admin.display
    def get_value_to_3dp(self, obj):
        return ""%.3f"" % obj.bar
}}}

However, if you use either of the more 'modern'-style Python string-formatting methods (i.e. [https://docs.python.org/3/tutorial/inputoutput.html#the-string-format-method str.format] or [https://docs.python.org/3/tutorial/inputoutput.html#formatted-string-literals formatted string-literals]), the specified string is not displayed using the specified formatting, i.e. this:
{{{
class ModelFoo_Admin(admin.ModelAdmin):
    @admin.display
    def get_value_to_3dp(self, obj):
        return ""{0:3f}"".format(obj.bar)
}}}
or this:
{{{
class ModelFoo_Admin(admin.ModelAdmin):
    @admin.display
    def get_value_to_3dp(self, obj):
        return f'{obj.bar:3f}'
}}}
display the output string to the default number of decimal-places (in my case, 6), with trailing zeroes, rather than to 3 decimal places as expected.

I don't understand why there would be any difference between these approaches, so I am assuming this is a bug rather than the intended behaviour."	Bug	new	contrib.admin	4.2	Normal		admin, display, string, format,	Stephen Skett	Unreviewed	0	0	0	0	0	0
