Hi Anthony,

Thanks a lot for your help.

Le vendredi 21 novembre 2014 17:15:44 UTC+1, Anthony a écrit :
>
>
> Can you show more of your code? In particular, how are you displaying the 
> results to determine the order? Are you sure there is not some subsequent 
> step that is re-ordering the records?
>
> My code is exactly like this one:

db.define_table('person',
                Field('name'))
db.define_table('thing',
                Field('name'))

db.define_table('ownership',
                Field('person', 'reference person'),
                Field('thing', 'reference thing'))

def populate_db():
    db.person.insert(name='alex')
    db.person.insert(name='bob')
    db.person.insert(name='curt')
    db.thing.insert(name='boat')
    db.thing.insert(name='chair')
    db.thing.insert(name='shoes')
    db.ownership.insert(person=1, thing=1) # Alex owns Boat
    db.ownership.insert(person=1, thing=2) # Alex owns Chair
    db.ownership.insert(person=2, thing=3) # Bob owns Shoes
    db.ownership.insert(person=3, thing=1) # Curt owns Boat too
    db.ownership.insert(person=2, thing=1) # Bob owns Boat too
return
def m2m_query():
    persons_and_things = db((db.person.id==db.ownership.person)& 
(db.thing.id==db.ownership.thing))
    all_rows = persons_and_things.select(db.person.name, db.thing.name, 
orderby='<random>')
    alex_rows = 
persons_and_things(db.person.name=='alex').select(db.person.name, db.thing.name)
    boat_rows = 
persons_and_things(db.thing.name=='boat').select(db.person.name, db.thing.name, 
orderby='<random>')
return dict(all_rows = all_rows, alex_rows=alex_rows, boat_rows=boat_rows, 
lastSQL=db._lastsql)



I am sure that the display of the results is ok and that there is no 
re-ordering of the records.
The db._lastsql provides me with the correct SQL query and the rows shown 
are those resulting from the query.
 
SELECT  person.name, thing.name FROM person, ownership, thing WHERE 
(((person.id = ownership.person) AND (thing.id = ownership.thing)) AND 
(thing.name = 'boat')) ORDER BY Random();

Are you absolutely sure that:
>
> rows=db(...).select().sort(lambda row: random.random())
>
>
> produces the same Rows object as:
>
> rows=db(...).select()
>
>
> That would imply that either the .sort method or the built-in 
> random.random method are not working.
>
No, they're different. The problem lies in somewhere else.

The problem only exist on the website at PythonAnywhere. On my local 
machine, everything is fine.
Since I don't want to lose your time and mine, I'm going to "clean up" my 
code (I am not a professional developer !!), the database and install the 
application again.
I'll come back later if the problem remains.
Thanks a lot for your help and your time.
I really appreciate.

Dominique 

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to