def gen(count, dicts, get_string_function): user = User.objects.all()[0] date_now = now() total = count while 0 < count: stdout.write("%d\r" % (total - count)) stdout.flush() count -= 1 note = Note() note.user = user note.pub_date = date_now note.title = get_string_function(dicts, randrange(20, 100)) note.body = get_string_function(dicts, randrange(500, 1000)) note.save()