def add_snake(email, name, length, species, is_venomous): snake = Snake(name=name, length=length, species=species, is_venomous=is_venomous) snake.save() num_updated = Owner.objects(email=email).update_one( push__snake_ids=snake.id) if num_updated != 1: raise Exception("No account with email {}".format(email))
def find_snakes_for_user(account: Owner) -> List[Snake]: account = find_account_by_email(account.email) # get fresh copy query = Snake.objects(id__in=account.snake_ids).all( ) # find all snake ids in account.snake_ids snakes = list(query) return snakes
def add_snake(account, name, length, species, is_venomous) -> Snake: snake = Snake() snake.name = name snake.length = length snake.species = species snake.is_venomous = is_venomous snake.save() owner = find_account_by_email(account.email) owner.snake_ids.append(snake.id) owner.save() return snake
def add_snake(account: Owner, name: str, length: float, species: str, is_venomous: bool) -> Snake: snake = Snake() snake.name = name snake.length = length snake.species = species snake.is_venomous = is_venomous snake.save() owner, msg = find_account_by_email(account.email, account.password) owner.snake_ids.append(snake.id) owner.save() return snake
def add_snake(account: Owner, nme, spcs, len, is_ven): snake = Snake() snake.species = spcs snake.length = len snake.name = nme snake.is_venomous = is_ven snake.save() owner = find_account_by_email(account.email) owner.snake_ids.append(snake.id) owner.save() return snake
def add_snake(account: Owner, name: str, species: float, length: float, venomous: bool) -> Snake: snake = Snake() snake.name = name snake.species = species snake.length = length snake.venomous = venomous snake.save() account = find_account_by_email(account.email) # get fresh copy account.snake_ids.append(snake.id) account.save() return snake
def get_snakes_for_user(user_id: bson.ObjectId) -> List[Snake]: owner = Owner.objects(id=user_id).first() snakes = Snake.objects(id__in=owner.snake_ids).all() return list(snakes)
from data.owners import Owner import mongoengine from data.snakes import Snake owner = Owner(name=name, email=email) # owner.id is None owner.save() # owner.id is objectId('whatever object id is') snakes = [snake1, snake2] # ... Snake.objects().insert(snakes)
def get_snakes_for_user(user_id: bson.ObjectId) -> List[Snake]: owner = Owner.objects(id=user_id).first() # pylint: disable=no-member snakes = Snake.objects(id__in=owner.snake_ids).all() # pylint: disable=no-member return list(snakes)
def get_snakes_for_user(account: Owner): query = Snake.objects(id__in=account.snake_ids).all() snakes = list(query) return snakes