def find_or_create(klz, user_id, deck_id, user_card_id, question, answer): try: card = s.query(Card).filter(and_(Card.user_card_id == user_card_id, Card.user_id == user_id)).one() except NoResultFound, e: card = Card(user_id, deck_id, user_card_id, question, answer) s.add(card) s.commit()
def find_or_create(klz, user_id, name): try: deck = s.query(Deck).filter(and_(Deck.name == name, Deck.user_id == user_id)).one() except NoResultFound, e: deck = Deck(user_id, name) s.add(deck) s.commit()