def register_user(user_id, tournament_id): """ Registers a user into a tournament :param user_id: Id of a user :param tournament_id: Id of a tournament :return: True if user is registered and false otherwise """ the_tournament = Tournament.objects.get(id=tournament_id) if the_tournament.current_participants < the_tournament.max_participants: the_user = User.objects.get(id=user_id) reg = Registration() reg.user = the_user reg.tournament = the_tournament reg.save() return True else: return False