1

I am using MySQL with Peewee. Everything has worked nicely, but now I can't order my query in a random order.

Based on the documentation I've tried the following code:

import peewee as pw
objz = featured.select().order_by(fn.Rand()).limit(5)

After calling the query I got the following error:

builtins.NameError

NameError: name 'fn' is not defined

So I would like to ask somebody who is more familiar with Peewee, that fn is something that I need to import or implement somehow? I already tried order_by(tablename.Rand()).limit(5), but it didn't solve the issue.

I assume I made a beginner mistake somewhere, but I can't figure it out.

halfer
  • 19,824
  • 17
  • 99
  • 186
rihekopo
  • 3,241
  • 4
  • 34
  • 63

1 Answers1

4

It should be

pw.fn.Rand()

or,

from peewee import fn
coleifer
  • 24,887
  • 6
  • 60
  • 75
altunyurt
  • 2,821
  • 3
  • 38
  • 53