Hi Selwin,

Considering "There should be one-- and preferably only one --obvious way to 
do it", I definitely prefer to rely on order_by to do the ordering, not on 
first. 

.order_by('name').first()

is clear and readable in my opinion.

Wim

On Sunday, 12 May 2013 06:55:04 UTC+2, Selwin Ong wrote:
>
> Hi everyone,
>
> I opened a new pull request implementing Shai's suggestions (I didn't 
> overwrite the current branch so we can still compare the two 
> implementations if needed).
>
> I initially modeled "first()" and "last()"'s behaviors to mimic 
> "latest()", but in this new pull request, you can pass multiple field names 
> into "first()" and "last()" so it behaves like "order_by()". It's more 
> flexible and requires less typing, but I wonder if we should just get rid 
> of the optional field arguments and rely on "order_by" for ordering. "There 
> should be one-- and preferably only one --obvious way to do it".
>
> Thoughts?
>
> The new pull request is here: https://github.com/django/django/pull/1056
>
> Best,
> Selwin
>
> On Sunday, May 12, 2013 4:23:33 AM UTC+7, Shai Berger wrote:
>>
>> Hi Selwin, 
>>
>> On Saturday 11 May 2013, Selwin Ong wrote: 
>> > Hi everyone, 
>> > 
>> > I submitted a pull request implementing "first()" and "last()" here: 
>> >  https://github.com/django/django/pull/1054 
>> > 
>> > Comments welcome! 
>> > 
>> You implemented the "order_by" parameter as taking only one field name; 
>> this is 
>> inconsistent with the way ordering is done elsewhere  -- both the 
>> queryset 
>> order_by() method, and the model meta ordering option, take a list of 
>> field 
>> names, each optionally prefixed by "-". 
>>
>> While I can see reason in going for a simpler implementation, I think it 
>> is 
>> much preferable to have a consistent API; and even if the simpler 
>> implementation is preferred, you should take care of a more friendly 
>> error 
>> message for someone who would call qset.first("a","b") or even 
>> qset.last("-a") 
>> [the latter may seem to make no sense -- "if that's what you want, call 
>> qset.first('a')" -- but may reasonably arise in situations where the 
>> ordering 
>> field is received as an argument]. 
>>
>> Shai. 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" 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 http://groups.google.com/group/django-developers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to