Hi Moises,
I think you may be able to solve this by adding a sort order by key, as follows:
q_next = q.order(MaqHistMov.idsm, MaqHistMov.key)
q_previous = q.order(-MaqHistMov.idsm, -MaqHistMov.key)
FWIW, here is an example that I think represents what you are doing:
class M(ndb.Model):
a = ndb.IntegerProperty()
b = ndb.IntegerProperty()
M(a=1, b=1).put()
M(a=2, b=1).put()
M(a=3, b=1).put()
M(a=4, b=2).put()
M(a=5, b=3).put()
M(a=6, b=4).put()
q = M.query()
q_asc = q.order(M.b, M.key)
q_desc = q.order(-M.b, -M.key)
r1, c1, m1 = q_asc.fetch_page(3)
print [r.a for r in r1]
r2, c2, m2 = q_asc.fetch_page(3, start_cursor=c1)
print [r.a for r in r2]
r3, c3, m3 = q_desc.fetch_page(3, start_cursor=c2.reversed())
print [r.a for r in r3]
r4, c4, m4 = q_desc.fetch_page(3, start_cursor=c3)
print [r.a for r in r4]
This outputs the following for me, which I think is correct:
[1, 2, 3]
[4, 5, 6]
[6, 5, 4]
[3, 2, 1]
Note that the final query does not reverse the cursor, since its start
cursor is already reversed. So you only reverse the cursor upon
reversing query directions.
--Guido
On Mon, Sep 24, 2012 at 4:12 AM, Moises Belchin <[email protected]> wrote:
> Hi Guido,
>
> Thanks in advance to take your time and figure out our problem.
>
> I send you the code we're using and an image to show you our model and some
> entities to review our query results.
>
> The first problem we encountered is that idsm property must be indexed if
> you want to order by MaqHistMov.idsm desc. If you use limit, offset query
> fetch this requirement doesn't exist.
--
--Guido van Rossum (python.org/~guido)
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.