Opened 9 years ago

Closed 8 years ago

Last modified 7 years ago

#6089 closed (fixed)

Remove ordering for contrib.auth User model

Reported by: Leah Culver Owned by: Erik Karulf
Component: Contrib apps Version: master
Severity: Keywords:
Cc: erik@…, lau@…, spacetaxi@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

In contrib.auth the User model has:

ordering = ('username',)

While it is very nice for small applications to have pretty ordered output, it's a bit hard on applications with many users (such as pownce.com). One concern is there might be applications that depend on this ordering in the User model and it would be nice not to break this functionality. However, it might be worth doing to make Django "scale"... ugh.

Attachments (2)

unordered-auth.diff (589 bytes) - added by Erik Karulf 9 years ago.
Removed ordering by default from User and Group
unordered-auth-2.diff (981 bytes) - added by Erik Karulf 9 years ago.
Same as above with added ordering in admin

Download all attachments as: .zip

Change History (11)

comment:1 Changed 9 years ago by Erik Karulf

Cc: erik@… added
Has patch: set
Triage Stage: UnreviewedDesign decision needed

I'm a strong +1 on this as well. I'll submit the small 2 line patch, though it defiantly needs a design decision.

Changed 9 years ago by Erik Karulf

Attachment: unordered-auth.diff added

Removed ordering by default from User and Group

comment:2 Changed 9 years ago by Jacob

Triage Stage: Design decision neededAccepted

Accepted, with the comments I told ekarulf IRL.

Changed 9 years ago by Erik Karulf

Attachment: unordered-auth-2.diff added

Same as above with added ordering in admin

comment:3 Changed 9 years ago by anonymous

Cc: lau@… added

comment:4 Changed 9 years ago by Erik Karulf

Owner: changed from nobody to Erik Karulf
Status: newassigned
Triage Stage: AcceptedReady for checkin

I bumped into this again when migrating a large table of users into Django.

The patch seems fairly benign, ready for checkin?

comment:5 Changed 8 years ago by Malcolm Tredinnick

Resolution: fixed
Status: assignedclosed

(In [7806]) Fixed #6089 -- Removed default ordering on the User class.
Admin users are still ordered, since we add it in specially for Admin. Slightly
backwards incompatible.

Patch from Erik Karulf.

comment:6 in reply to:  5 Changed 8 years ago by spacetaxi

I have a model with a many-to-many relation to the contrib.auth User model. Now when I open the admin form (newforms-admin) to edit my model, the user-selection widget contains unsorted users... This is nearly unusable. Prior to [7806] the selection widget was sorted. I need this widget to show sorted users, but what's the right way to get them sorted again? (Maybe this is dumb question, but currently I don't see an elegant solution...)

comment:7 Changed 8 years ago by spacetaxi

Cc: spacetaxi@… added

comment:8 Changed 7 years ago by Benjamin Wohlwend

Just in case someone else has the same problem as I (and spacetaxi, as it seems) had and stumbles over this ticket: this is how I restored order (ahem) of ForeignKeys to the User model in the Admin

    class MyModelForm(forms.ModelForm):
        def __init__(self, *args, **kwargs):
            super(MyModelForm, self).__init__(*args, **kwargs)
            self.fields['user'].choices = [('', 10*'-')] + list(User.objects.all().values_list('id', 'username').order_by('username'))

        class Meta:
            model = MyModel

    class MyModelAdmin(admin.ModelAdmin):
        form = MyModelForm

comment:9 Changed 7 years ago by dannyman

Hello,

I've spent a few hours trying unsuccessfully to sort the usernames in my admin interface, posting a query on Stack Overflow which led me here:

http://stackoverflow.com/questions/1474135/django-admin-ordering-of-foreignkey-and-manytomanyfield-relations-referencing-us

While I think its great that piquadrat has a solution, (thanks!) can I just say "eek" and suggest that there ought to be some sane way to specify how to sort users in the admin inteface? Thanks!

Note: See TracTickets for help on using tickets.
Back to Top