Tuesday, April 28, 2015

forcing user model to return first_name last_name if exists


I have many places in my app where user (from user model) is displayed: templates, forms, fliters, tables etc.
It is displayed as username everywhere.

I want it to be displayed as first_name/last_name.

I can do that with monkey patching:

def patch(*args, **kwargs):
    get_user_model().__str__ = my_smart_str_func

I use "request_started" to make sure all models are loaded. (BTW, does there is something like "models loaded" signal?).

How ever, I feel it a little bit hacky. There should be more pythonic way to do that. Am I miss something?

You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b483b4a8-ee4a-4cdb-ad81-769fabf4b0ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment