Code

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#1298 closed enhancement (invalid)

allow customized sort in model.get_list() and META ordering

Reported by: mattimustang@… Owned by: adrian
Component: Core (Other) Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I would like to be able to sort a field by more than just its alpha or numerical ascending/descending order:

eg. With the model:

class A(meta.Model):
    ip = meta.IPAddressField()
    class META: ordering = ['ip']

The list of IP's gets sorted like this:

192.168.1.1
192.168.1.10
192.168.1.11
192.168.1.2
192.168.1.20

rather than how I would like to have it sorted:

192.168.1.1
192.168.1.2
192.168.1.10
192.168.1.11
192.168.1.20

Is it possible to add a model.get_list(order_by=('ip', sort_ip_function)) or as well as some equivalent in META like 'ordering = (('ip', sort_ip_function),)' option to allow some kind of customized sorting to happen?

thanks

matthew

ps. Do Managers in magic-removal address this?

Attachments (0)

Change History (2)

comment:1 Changed 8 years ago by lukeplant

Django does all it's ordering using SQL, so this isn't feasible. You could do extra ordering after retrieving the data, but it wouldn't work as expected: these don't do the same thing:

[get all items] -> [sort by (1 then 2)]

[get all items] -> [sort by 1] -> [sort by 2]

The only way to do this at all would be to use some server side custom sorting function, which would depend on what is available with your choice of database.

comment:2 Changed 8 years ago by adrian

  • Resolution set to invalid
  • Status changed from new to closed

Closing for the reason Luke pointed out above.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.