def handle(self, *args, **options): Tag.objects.bulk_create([Tag(tag=t[0], slug=t[1]) for t in tags], ignore_conflicts=True) names = generate_username(int(options["num_users"])) User = get_user_model() users = [ User.objects.create_user(username=n, password=self.password) for n in names ] print(users) gen = DocumentGenerator() gen.init_word_cache(5000) gen.init_sentence_cache(5000) for user in users: user = User.objects.get(username=user.username) user.profile.bio = gen.sentence() user.profile.save() articles = Article.objects.bulk_create([ Article( slug=make_slug(gen.sentence()), title=gen.sentence(), description=gen.sentence(), body=gen.paragraph(), author=user.profile, ) # Make sure every user has at least 1 article for _ in range(random.randrange(1, self.article_upper_bound)) ]) print(articles) # Make sure every article has 1 tag, could add more later for article in articles: article.tags.add(Tag.objects.get(slug=random.choice(tags)[1])) self.stdout.write(self.style.SUCCESS(f"Created {len(users)} users"))
def test_cache(self): gen = DocumentGenerator() gen.init_word_cache(5000) gen.init_sentence_cache(5000) self.assertEqual(len(gen.word_cache), 5000) self.assertEqual(len(gen.sentence_cache), 5000)
def generate_Documents(): gen = DocumentGenerator() gen.init_word_cache(5) gen.init_sentence_cache(5) gen.word_cache = ['Is', 'this', 'working', 'pls', 'work'] gen.sentence_cache = [ 'This is a great step in the right direction', 'Every moment is the paradox of now or never', 'World will judge you on this moment' ] print(gen.word_cache) print(gen.sentence_cache) template = { 'id': 'guid', 'status': ['online', 'offline', 'dnd', 'anonymous'], 'age': 'small_int', 'homepage': 'url', 'name': 'name', 'headline': 'sentence', 'text': 'paragraph' } gen.set_template(template) documents = gen.documents(10) print(documents[0])