def handle(self, *args, **options): number_teachers = options['number_teacher'] try: for _ in range(number_teachers): Teacher.generate_teacher() except Exception as ex: raise CommandError(f'Data added fail! {ex}') self.stdout.write( self.style.SUCCESS(f'Data added successfully! {number_teachers}'))
def generate_teachers(request): amount = int(request.GET['amount']) lst = [] if amount > 200: amount = 5 for _ in range(amount): a = Teacher.generate_teacher() lst.append(a.Teacher_first_name) lst.append('<br>') return HttpResponse(f'generated {amount} teachers: <br> {lst}')
def handle(self, *args, **options): Teacher.objects.all().delete() group = list(Groups.objects.all()) quantity = args[0] if quantity > 200: quantity = 5 print(f'Generating {quantity} teachers:') lst = [] for _ in range(quantity): a = Teacher.generate_teacher(group) lst.append(a) for teach in lst: print(teach.Teacher_first_name, " ", teach.Teacher_second_name)
def generate_teachers(request): for _ in range(1): Teacher.generate_teacher() abc = Teacher.objects.all() return HttpResponse(abc)
def handle(self, *args, **kwargs): count = kwargs['count'] for _ in range(count): Teacher.generate_teacher() self.stdout.write(self.style.SUCCESS(f'Created: {count} teachers'))