Skip to content

Instantly share code, notes, and snippets.

@kholidfu
Created May 21, 2017 17:47
Show Gist options
  • Save kholidfu/91318708b2fc9aca9ec86aaa5119aaed to your computer and use it in GitHub Desktop.
Save kholidfu/91318708b2fc9aca9ec86aaa5119aaed to your computer and use it in GitHub Desktop.
get random id from django model
import random
from app.models import Collection
c = Collection.objects.filter(done=True).values('id')
rid = [i['id'] for i in c]
random.choice(rid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment