Junior — Senior
Registering a book along with its covers via API
livecode
Task condition
When a POST request responsible for creating a new book is received, the create_book function is called. It creates a Book model record and then creates related BookCover model records.
A code review is needed: assess the correctness and reliability of the entity creation process, and pay attention to potential issues with transactions and optimization.
def create_book(data: dict):
cover_list: list[dict] = data.pop('covers')
new_book = Book.objects.create(**data)
for cover in cover_list:
BookCover.objects.create(**cover, book_id=new_book.id)