Junior — Senior
Implementation of creating a book along with its covers
livecode
Task condition
It is necessary to ensure that the process of creating a Book record works correctly, and then related BookCover records are automatically created using information from the covers list. It is important to verify that when forming covers, the book_id field is assigned only the identifier of the newly created book.
def create_book(validate_data: dict):
covers: list[dict] = validate_data.pop('covers')
book = Book.objects.create(**validate_data)
for cover in covers:
BookCover.objects.create(**cover, book_id=book.id)