def start(self): c = int(self.count / 10) for i in range(c): t1 = Team( name='team_{}'.format(i), games=self.count, ) t2 = Team( name='team_{}'.format(i), games=self.count, ) t1.save(using='db1') t2.save(using='db2') for j in range(10): u = User(username='******'.format(j + 10 * i), email='ivan@ivan{}.ru'.format(j + 10 * i)) u.set_password('ivan123') u.first_name = 'ivan{}'.format(j + 10 * i) u.last_name = 'ivanov{}'.format(j + 10 * i) ran_db = random.randint(1, 2) u.id = int(get_pk() + str(ran_db)) print(u.id) u.save(using='db' + str(ran_db)) if ran_db == 1: tu = UserTeam( user=u, team=t1, ) else: tu = UserTeam( user=u, team=t2, ) tu.save(using='db' + str(ran_db)) cc = int(self.count / 100) for i in range(cc): t = Turn(name='turn{}'.format(i)) t.save(using='db1') t.save(using='db2') for j in range(10): m = Match(name='match{}'.format(j + 10 * i), turn_id=t.id) m.save(using='db1') m.save(using='db2') for l in range(10): g = Game(name='game___{}'.format(l + 10 * j + 100 * i), match_id=m.id) ran_db = random.randint(1, 2) g.id = int(get_pk() + str(ran_db)) g.save(using='db' + str(ran_db)) tm = Team.objects.using('db' + str(ran_db)).filter( name='team_{}'.format(j + 10 * i))[0] gt = GameTeam(game=g, team=tm) gt.save(using='db' + str(ran_db))