From c07aa873d8785ecbae06692b430afb6f29207854 Mon Sep 17 00:00:00 2001 From: Arnau Casas <33383702+Casassarnau@users.noreply.github.com> Date: Thu, 11 Nov 2021 12:54:48 +0100 Subject: [PATCH] Updated to Django3 --- hardware/models.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/hardware/models.py b/hardware/models.py index c68d00e..db9a551 100644 --- a/hardware/models.py +++ b/hardware/models.py @@ -50,7 +50,7 @@ class Item(models.Model): """Represents a real world object identified by label""" # Hardware model/type - item_type = models.ForeignKey(ItemType) + item_type = models.ForeignKey(ItemType, on_delete=models.CASCADE) # Identifies a real world object label = models.CharField(max_length=20, unique=True) # Is the item available? @@ -85,17 +85,18 @@ class Borrowing(models.Model): """ objects = BorrowingQuerySet.as_manager() - user = models.ForeignKey(User) - item = models.ForeignKey(Item) + user = models.ForeignKey(User, on_delete=models.DO_NOTHING) + item = models.ForeignKey(Item, on_delete=models.DO_NOTHING) # Instant of creation picked_up_time = models.DateTimeField(auto_now_add=True) # If null: item has not been returned yet return_time = models.DateTimeField(null=True, blank=True) # Borrowing handled by - borrowing_by = models.ForeignKey(User, related_name='hardware_admin_borrowing') + borrowing_by = models.ForeignKey(User, related_name='hardware_admin_borrowing', on_delete=models.DO_NOTHING) # Return handled by (null until returned) - return_by = models.ForeignKey(User, related_name='hardware_admin_return', null=True, blank=True) + return_by = models.ForeignKey(User, related_name='hardware_admin_return', null=True, blank=True, + on_delete=models.SET_NULL) def get_picked_up_time_ago(self): return str(timezone.now() - self.picked_up_time) @@ -144,11 +145,11 @@ class Request(models.Model): objects = RequestQuerySet.as_manager() # Requested item type - item_type = models.ForeignKey(ItemType) + item_type = models.ForeignKey(ItemType, on_delete=models.CASCADE) # Hacker that made the request - user = models.ForeignKey(User) + user = models.ForeignKey(User, on_delete=models.CASCADE) # Borrowing derived from this request - borrowing = models.ForeignKey(Borrowing, null=True, blank=True) + borrowing = models.ForeignKey(Borrowing, null=True, blank=True, on_delete=models.CASCADE) # Instant of creation request_time = models.DateTimeField(auto_now_add=True)