def create_place(self, arg): for _ in range(arg): num_tags = random.randint(1, 5) PlaceFactory.create(tags__num=num_tags)
def handle(self, *args, **options): # noqa optional_arguments = 0 for item in list(OPTIONS_AND_FINCTIONS): if options[item]: optional_arguments += 1 with factory.Faker.override_default_locale("ru_RU"): OPTIONS_AND_FINCTIONS[item](options[item][0]) self.stdout.write( self.style.SUCCESS( f"{options[item][0]} {item} created successfully" ) ) if optional_arguments == 0: try: if City.objects.count() > len(CITIES): raise MyException() with factory.Faker.override_default_locale("ru_RU"): for city_name in CITIES: CityFactory(name=city_name) CityFactory.create_batch(10) EventFactory.create_batch(200) CuratorFactory.create_batch(15) RightTagFactory.create_batch(10) for _ in range(70): num_tags = random.randint(1, 5) RightFactory(tags__num=num_tags) for _ in range(70): num_events = random.randint(0, 5) UserFactory(num_events=num_events) QuestionTagFactory.create_batch(15) for _ in range(70): num_tags = random.randint(1, 5) QuestionFactory.create(tags=num_tags) QuestionFactory.create_batch(5) QuestionFactoryWithoutAnswer.create_batch(5) PlacesTagFactory.create_batch(15) for _ in range(70): num_tags = random.randint(1, 5) PlaceFactory.create(tags__num=num_tags) GuideFactory.create_batch(70) MovieTagFactory.create_batch(10) for link in link_movie_list: num_tags = random.randint(1, 5) MovieFactory.create(link=link, tags__num=num_tags) MeetingFactory.create_batch(50) ArticleFactory.create_batch(70) BookTagFactory.create( name="Художественные", slug="hudozhestvennye", color="#C8D1FF", ) BookTagFactory.create( name="Научные", slug="nauchnye", color="#FC8585" ) BookFactory.create_batch(50) VideoTagFactory.create_batch(15) for link in link_video_list: num_tags = random.randint(1, 5) VideoFactory.create(link=link, tags__num=num_tags) StoryFactory.create_batch(30) StoryImageFactory.create_batch(100) MainFactory.create() self.stdout.write( self.style.SUCCESS("The database is filled with test data") ) except MyException: self.stdout.write( self.style.ERROR( "The database is already filled with standard test " "data. To top up individual tables, use the arguments." ) )