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.
It should be
pw.fn.Rand()
or,
from peewee import fn