mdn / django-locallibrary-tutorial

Local Library website written in Django; example for the MDN server-side development Django module: https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handle case where Book belonging to Bookinstance is deleted.

hamishwillee opened this issue · comments

Before submitting the issue, confirm that you've checked everything in the following list, and mark them as completed here:

  • Issue is reproducible on this repository by following the quick-start instructions.
  • A clean/fresh database was used when the issue was encountered.
  • Information about the environment setup when the issue was encountered is included in the issue.
  • Output logs are included in the issue.

What was incorrect, unhelpful, or unexpected?

The problem is described here mdn/content#27895 and the "base" of the solution is described in comment here: mdn/content#27895 (comment)

In short, this example stops at the same point as the tutorial challenge, which was creating forms for create, modify, delete, of books. It does not show any code for bookinstances.

However if you were to implement a bookinstance code, assign a book, and then you delete the book you get an error - because the book model requires you cannot delete a book unless all its instances are first deleted.

What did you expect to see?

We need to implement the bookinstance stuff as well (to ease testing) and override the book implementation to handle the error and provide a new view in this error case.

We should also create a Test for this case in the test cases, though that is not essential.

Output logs

Nope.

Do you have anything more you want to share?

Nope