Skip to content

Instantly share code, notes, and snippets.

@romanbarczynski
Created April 24, 2015 19:36
Show Gist options
  • Save romanbarczynski/2698deada57d74c161d1 to your computer and use it in GitHub Desktop.
Save romanbarczynski/2698deada57d74c161d1 to your computer and use it in GitHub Desktop.
Milkman words generator for varchar
words = [
'Alfa',
'Bravo',
'Charlie',
'Delta',
'Echo',
'Foxtrot',
'Golf',
'Hotel',
'India',
'Juliet',
'Kilo',
'Lima',
'Mike',
'November',
'Oscar',
'Papa',
'Quebec',
'Romeo',
'Sierra',
'Tango',
'Uniform',
'Victor',
'Whiskey',
'X-ray',
'Yankee',
'Zulu']
def random_4_words(max_length, *args, **kwargs):
random_words = "%s %s %s %s" % (
random.choice(words), random.choice(words),
random.choice(words), random.choice(words))
if len(random_words) > max_length:
from milkman.dairy import generators
random_words = generators.random_string(max_length, *args, **kwargs)
return random_words
def random_4_words_maker(field, *args, **kwargs):
from milkman.dairy import generators
max_length = getattr(field, 'max_length', generators.DEFAULT_STRING_LENGTH)
return generators.loop(lambda: random_4_words(max_length, *args, **kwargs))
milkman.registry.add_generator(models.CharField, random_4_words_maker)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment