Skip to content

Commit

Permalink
Updated to Django3
Browse files Browse the repository at this point in the history
  • Loading branch information
Casassarnau committed Nov 11, 2021
1 parent e5f68b0 commit c07aa87
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions hardware/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit c07aa87

Please sign in to comment.