Contributors mailing list archives


Re: Sort function field, which is not stored in the db

Holger Brunn
- 11/01/2018 09:44:09
> I have a function field, which I don`t want to store in the db.


> The problem is that I want to be able to sort by this field in a tree

> view via click on the column header.


> Is there a way to do this?

with jumping through a lot of hoops, there is. Reassess if you really
don't want to store the field, that's a world simpler and if it's not a
crazy amount of data, postgres doesn't care so much about an extra
column. Also think if you need to store all of the data for sorting, if
you can generate a numeric sort key, you could just save that, much faster.

If you really think you can't store this, you're up for some pain:
- override
such that comes
back True for your field
- override
where you do the sorting manually. You'll have to analyze the sort
parameter, remove your field before passing it to super, and then do the
right thing for sorting afterwards. Don't expect performance miracles,
and I think supporting all features of sorting will actually be cumbersome.

Therp - Maatwerk in open ontwikkeling

Holger Brunn - Ontwerp en implementatie

phone: +31 (0)20 3093096