Sobes.tech
Junior — Senior

Creating a book record with covers - Option 1

livecode

Task condition

It is necessary to ensure that the process of creating a Book entity is correctly accompanied by the creation of related BookCover records based on the provided cover data. Check that the book identifier is correctly passed when forming each cover.

def create_book(data: dict):
    cover_list: list[dict] = data.pop('covers')
    new_book = Book.objects.create(**data)
    for cover_item in cover_list:
        BookCover.objects.create(**cover_item, book_id=new_book.id)
Creating a book record with covers - Option 1 - Live… - sobes.tech