﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26141	__lt__ for model instances	Sven R. Kunze	nobody	"We need to sort a list of model instances (not a queryset).

After some research, we didn't find a standard way to do this with Django model instances. Would it be possible to implement {{{__lt__}}} for model instances via the meta class mechanism?

Currently, we write a wrapper where we implemented the following {{{__lt__}}} method:

{{{
def __lt__(self, other):
    for criteria in self.object._meta.ordering:
        field = criteria[1:] if criteria.startswith('-') else criteria
        mine = getattr(self.object, field)
        theirs = getattr(other.object, field)
        if isinstance(mine, unicode):
            mine = locale.strxfrm(mine.encode('utf8'))
            theirs = locale.strxfrm(theirs.encode('utf8'))
        if mine == theirs:
            continue
        if criteria.startswith('-'):
            return mine > theirs
        return mine < theirs
    raise NotImplementedError
}}}

Please note, that the implementation is locale-aware."	New feature	closed	Database layer (models, ORM)	dev	Normal	wontfix		tzanke@…	Unreviewed	0	0	0	0	0	0
