0

I have a function which I'm trying to make return a list of ordered keys (which are in date format). I have

        data = database.child('users').child(num).child('details').get().val()

and then

        return render(request, "page2.html", {'list':(list(data.keys()))})

This works correctly but returns them in random order in terms of key values.

I've tried variations of something like:

        data = database.child('users').child(num).child('details').order_by_key().get().val()

or

        data = database.child('users').child(num).child('details').order_by_key().get()

but I'm obviously missing something.

Thanks

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
fdgnhgdh
  • 77
  • 4

1 Answers1

0

When you call .val() the data gets converted to a dictionary (or the equivalent Python structure) and any information about the order is lost.

To maintain the order, you must process the results in order by using Pyrebase's each function.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807