Пример #1
0
client = pymongo.MongoClient(
    "mongodb+srv://nico:[email protected]/test?retryWrites=true&w=majority"
)

db = client.mydb

authors = db.authors
editors = db.editors
books = db.books

nico_author = Author(authors, 'Nicolas', 'Blanchard')
nico_author.save()

kath_editor = Editor(editors, 'abcabcd', 'Kathleen Editor')
kath_editor.save()

bruxelles_book = Book(books, '1231232', 'Bruxelles: la ville')
bruxelles_book.editor = kath_editor._id
bruxelles_book.add_author(nico_author._id)
bruxelles_book.save()

nico_author.add_book(bruxelles_book._id)
nico_author.save()

kath_editor.add_book(bruxelles_book._id)
kath_editor.save()

bruxelles_book.delete()
nico_author.delete()
kath_editor.delete()
Пример #2
0
        available = input(f'Books available: ({book.available}): ').strip()
        if name:
            book.name = name
        if author:
            book.author = author
        if available:
            book.available = available
        if name or author or available:
            book.save()
            print('Details updated successfully')

    elif option == '9':
        book_id = input('Book ID: ')
        if confirm():
            member = Book.find_with_alert(book_id)
            Book.delete(book_id)
            print('Book deleted successfully')

    elif option == '10':
        member_id = input('Member id: ')
        member = Member.find_with_alert(member_id)
        if not member:
            continue
        book_id = input('Book id: ')
        print(member.assign_book(book_id))

    elif option == '11':
        member_id = input('Member id: ')
        member = Member.find_with_alert(member_id)
        if not member:
            continue