More useful output for User.__unicode__ allowing easy formatting of all admin forms that list users from settings
|Reported by:||Paul McLanahan||Owned by:||Paul McLanahan|
|Severity:||Keywords:||auth user model unicode|
|Cc:||Triage Stage:||Design decision needed|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
When choosing a user in an admin form for a model with a relationship to the django.auth.models.User model, the field always shows the username attribute, which in many systems isn't very informative. This patch would allow control over the formatting of those fields from the settings module.
This introduces a new setting named "AUTH_USER_STR_FORMATTER", which should be set to a callable that will be passed the User model instance and is expected to return a string to be used as a plain text representation of the User object.
# settings.py def user_str_formatter(user): fname = user.get_full_name() return "%s (%s)" % (fname, user.username) if fname else user.username AUTH_USER_STR_FORMATTER = user_str_formatter
Change History (6)
comment:1 Changed 8 years ago by
|Owner:||changed from nobody to Paul McLanahan|
|Status:||new → assigned|