OrderBy takes an expression - it doesn't have to be a single column. For 
example, this is valid:

(Lower('last_name') + Lower('first_name)).desc() == 
OrderBy(Lower('last_name') + Lower('first_name), descending=True)

On Friday, 25 November 2016 23:22:58 UTC+11, Mads Jensen wrote:
>
> On Tuesday, November 22, 2016 at 11:50:17 PM UTC+1, Josh Smeaton wrote:
>
>> Thanks for picking this up. I've been wondering if Window expressions 
>> would be possible, and what limitations we might have to make based on our 
>> ORM.
>>
>
> I was fortunate that the reporter posted a snippet to work from :) 
> Django's ORM is quite flexible, and adaptable. I remember seeing a video 
> with Alex Gaynor where he complained about its shortcomings, but that 
> seemed to have been sorted out.
>
> https://www.youtube.com/watch?v=GxL9MnWlCwo
>  
>
>> > 1. Since this is specific to postgres, I'm looking for a better place 
>> to 
>> put the actual Window-expression class, as well as axillary helpers 
>> (Order By, Partition and the frame). 
>>
>> I would create a new file beside expressions.py called 
>> django/db/models/window.py.
>>
>>
> Seems like a good starting point. I have been contemplating that 
> grouping.py could be a good name as well, in case somehow would like to add 
> WITHIN GROUP, or support for grouping sets (a bigger fish, since that means 
> appending stuff after GROUP BY etc.)
> Anyway, I have some window.py locally.
>  
>
>> > 2. Tests, and if the initial test-cases seem fair? I took a small 
>> sample 
>> of test cases related to some made-up salaries in a few departments.
>>
>> Yes, it's a good start, but I haven't thoroughly reviewed them yet 
>> either. It'll be easier to do when there's a proper PR.
>>
>
> I wouldn't call it proper, but I posted a pull request, and marked it 
> [WIP].
>
> > 3. The Order By-clause proposed in the initial code in the code only 
>> leaves room for one column (no expressions).
>>
>> Wouldn't the existing OrderBy type be sufficient? Really though, 
>> windowing should support a list of expressions (then call asc() or desc() 
>> on them).
>>
>
> Maybe I'm reading the code wrong, but doesn't OrderBy just refer to a 
> column, or are types of Expression/ExpressionWrapper also valid input?
>  
>
>> > 4. Would it be ok to add code for this in the base backend?
>>
>> Yes, if it makes the implementation nicer/easier for django and 3rd party 
>> backends. If having the code in the backend prevents *users* from creating 
>> their own windowing functions or modifying existing ones, then that's 
>> probably not ok. Django, backends, and users all need to be able to 
>> construct their own windowing expressions. You can certainly share code in 
>> the backend though, with things like PRECEDING ROW etc.
>>
>  
> I'm cleaning up things in the pull request. At least elements that are 
> mandatory are there, such as docs, tests and some code.
>  
>
>> > I'm relatively new to Django internals (it's fun and educational 
>> hacking 
>> on them), and it took me some time to read through the code and 
>> documentation for the ORM, and there are many facets of it I can still 
>> understand.
>>
>> None of us understand all of the ORM, and we're more than happy to have 
>> more people helping out, so thanks! If you create a PR (even if it's not 
>> ready, just mark is [WIP] for Work In Progress) it'll be easier to comment 
>> on specific things within the code and see all of the commits tied 
>> together. You're also more likely to get feedback on a PR and some guidance 
>> there too.
>>
>
> Good. I tend to have several small things in my commits, but I'll try to 
> work on individual things in this PR.
>
> Thanks for input.
>
> Kind regards,
> Mads
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/1e339090-3602-4f86-bb15-7fadc5f7ef0c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to