Skip to content

Commit 02132ec

Browse files
authored
Prevent book being deleted until all its instances are deleted (mdn#86)
* Cascade book deletion * Restrict deletion of book
1 parent 33a0465 commit 02132ec

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎catalog/models.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class BookInstance(models.Model):
7171
"""Model representing a specific copy of a book (i.e. that can be borrowed from the library)."""
7272
id = models.UUIDField(primary_key=True, default=uuid.uuid4,
7373
help_text="Unique ID for this particular book across whole library")
74-
book = models.ForeignKey('Book', on_delete=models.SET_NULL, null=True)
74+
book = models.ForeignKey('Book', on_delete=models.RESTRICT)
7575
imprint = models.CharField(max_length=200)
7676
due_back = models.DateField(null=True, blank=True)
7777
borrower = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)

0 commit comments

Comments
 (0)