Skip to content

Instantly share code, notes, and snippets.

@MattOates
Created November 14, 2017 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattOates/3c3f6ddafcfce1e44c2336bb49da6fe1 to your computer and use it in GitHub Desktop.
Save MattOates/3c3f6ddafcfce1e44c2336bb49da6fe1 to your computer and use it in GitHub Desktop.
The following code doesn't work, but a by hand tailored equivalent `random.choice(None or [None])` works just fine.
def random_rows(db, model, columns={}, num=100):
column_types = [ {'name': col.name, 'type': str(col.type)} for col in model.__table__.columns]
rows = []
for n in range(1, num):
rows.append([random.choice(columns.get(col['name']) or [None]) or __random_data(col['type']) for col in column_types])
return rows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment