def create_deck(deck_list, root_deck_id=None): deck = Deck() deck.root_deck_id = root_deck_id deck.create_date = datetime.now() if root_deck_id: last_index = Deck.filter_by(root_deck_id=root_deck_id).order_by(Deck.deck_index.desc()).all() deck.deck_index = last_index + 1 xcards = [] for card_string in deck_list: card, quant = parse_card(card_string) xcard = XDeckCard() xcard.quantity = quant xcard.card_id = card.id xcard.deck_id = deck.id xcards.append(xcard) return deck, xcards