I put a solituion for this in the form of where this is passed a user
object.

class UserChoiceField(forms.ModelChoiceField):
    '''
    Returns a select field with user names formatted by last and first
name
    where available and ordered by last name.
    '''
    def label_from_instance(self, obj):
        if obj.last_name or obj.first_name:
            display = ", ".join((obj.last_name, obj.first_name))
        else:
            display = obj.username
        return display

On Sep 4, 2:26 pm, Streamweaver <streamwea...@gmail.com> wrote:
> I had a model that lists an owner with a FK relationship to the Users
> table.
>
> When using model form the dropdown for the owner field defaults to the
> username.
>
> I'd like to override that to use a users name as the choice portion of
> the dropdown sorted by users last name but I'm having trouble thinking
> through how to do this.
>
> Can anyone point me to an example of something like this?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to