Opened 17 years ago

Closed 16 years ago

Last modified 15 years ago

#6089 closed (fixed)

Remove ordering for contrib.auth User model

Reported by: Leah Culver Owned by: Erik Karulf
Component: Contrib apps Version: dev
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: no UI/UX: no

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 17 years ago.
Removed ordering by default from User and Group
unordered-auth-2.diff (981 bytes ) - added by Erik Karulf 17 years ago.
Same as above with added ordering in admin

Download all attachments as: .zip

Change History (11)

comment:1 by Erik Karulf, 17 years ago

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.

by Erik Karulf, 17 years ago

Attachment: unordered-auth.diff added

Removed ordering by default from User and Group

comment:2 by Jacob, 17 years ago

Triage Stage: Design decision neededAccepted

Accepted, with the comments I told ekarulf IRL.

by Erik Karulf, 17 years ago

Attachment: unordered-auth-2.diff added

Same as above with added ordering in admin

comment:3 by anonymous, 17 years ago

Cc: lau@… added

comment:4 by Erik Karulf, 16 years ago

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 by Malcolm Tredinnick, 16 years ago

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.

in reply to:  5 comment:6 by spacetaxi, 16 years ago

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 by spacetaxi, 16 years ago

Cc: spacetaxi@… added

comment:8 by Benjamin Wohlwend, 15 years ago

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 by dannyman, 15 years ago

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