I started implementing such a sort, but discovered that all I needed to do 
(in my case) was sort by the text of the option itself (i.e. the options in 
the widget were "John Smith", "Thomas Jones", "Sally Wright", etc. and I 
just needed to sort those alphabetically. I just wrote a custom widget that 
calls OptionsWidget then sorts the resulting options.

On Saturday, November 21, 2015 at 12:16:41 PM UTC-7, Anthony wrote:
>
> Are you saying you don't want to sort by the labels at all, but by some 
> field(s) in auth_user that are otherwise not visible to the user? If so, I 
> don't think you'll be able to do that with IS_IN_DB. Instead, build (and 
> order) your set of values and labels manually, and then use the IS_IN_SET 
> validator. Alternatively, you could use the IS_IN_DB validator to do the 
> validation, and then override the "widget" attribute of the field with a 
> custom widget that generates the options as you want them.
>
> Anthony
>
> On Saturday, November 21, 2015 at 12:32:13 PM UTC-5, Hilton Shumway wrote:
>>
>> I'm building a site with a number of different tables linked to the 
>> auth_user table, namely mentors, judge, etc. A few different tables link 
>> indirectly to auth_user through foreign keys to those tables, for example 
>> abstract has a foreign key to mentor, which has a foreign key to auth_user.
>>
>> Now, it's possible the models should have been designed differently, but 
>> considering the site is in production now, changing that is a little 
>> difficult.
>>
>> My challenge is that various forms (including create/edit of abstracts, 
>> SQLFORM.grid-based searching of abstracts, etc) provide a select widget 
>> filled with available mentors, which is sorted according to mentor.id. 
>> I'd like to make that sorting alphabetical according to 
>> auth_user.first_name. After a bit of poking around I found 
>> http://stackoverflow.com/questions/28238708/how-to-set-default-orderby-in-a-web2py-table
>>  
>> (which doesn't seem to be documented in the web2py book), but that would 
>> only allow me to sort the select widget according to fields in mentor. If I 
>> try to pass orderby=db.auth_user.first_name to IS_IN_DB, I get a <class 
>> 'sqlite3.OperationalError'> no such column: auth_user.first_name error. 
>>
>> Am I missing something obvious? My guess is that when IS_IN_DB makes its 
>> query it doesn't select anything from auth_user, and attempts to reference 
>> those columns don't work. Is there a way to change this?
>>
>> I'm happy to provide more information if needed.
>>
>> Hilton
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to