def create_topics(self, options): number_of_topics = options['topics'] if number_of_topics is None and not options['only']: number_of_topics = DEFAULT_NUMBER if number_of_topics is not None and number_of_topics > 0: self.stdout.write('Start creating {} topcis ...'.format(number_of_topics)) current_topics = list(Topic.objects.values_list('id', flat=True)) new_topics = [] for i in range(number_of_topics): new_topics.append(Topic(title=get_random_string(20, self.chars))) Topic.objects.bulk_create(new_topics) items = [] for topic in Topic.objects.exclude(pk__in=current_topics): items.append(Item(content_object=topic, type=Item.AGENDA_ITEM)) Item.objects.bulk_create(items) self.stdout.write(self.style.SUCCESS('{} topcis successfully created.'.format(number_of_topics))) elif number_of_topics is not None and number_of_topics < 0: raise CommandError('Number for topics must not be negative.')
def create_topics(self, options): number_of_topics = options["topics"] if number_of_topics is None and not options["only"]: number_of_topics = DEFAULT_NUMBER if number_of_topics is not None and number_of_topics > 0: self.stdout.write(f"Start creating {number_of_topics} topcis ...") current_topics = list(Topic.objects.values_list("id", flat=True)) new_topics = [] for i in range(number_of_topics): new_topics.append(Topic(title=get_random_string(20, self.chars))) Topic.objects.bulk_create(new_topics) items = [] lists_of_speakers = [] for topic in Topic.objects.exclude(pk__in=current_topics): items.append(Item(content_object=topic, type=Item.AGENDA_ITEM)) lists_of_speakers.append(ListOfSpeakers(content_object=topic)) Item.objects.bulk_create(items) ListOfSpeakers.objects.bulk_create(lists_of_speakers) self.stdout.write( self.style.SUCCESS(f"{number_of_topics} topcis successfully created.") ) elif number_of_topics is not None and number_of_topics < 0: raise CommandError("Number for topics must not be negative.")
def test_topic_is_list_of_speakers_content_object(self): assert hasattr(Topic(), "get_list_of_speakers_title_information")
def test_topic_is_agenda_item_content_object(self): assert hasattr(Topic(), "get_agenda_title_information")