Permalink
Browse files

Fixed a bunch of shit. Too lazy to comment, just see commit changes.

  • Loading branch information...
1 parent 451a61e commit c3baaaf70774d7de0d0c031ed71fef5ca00025fc @Nifled Nifled committed Feb 17, 2017
View
Binary file not shown.
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-# Generated by Django 1.10.5 on 2017-02-16 06:15
+# Generated by Django 1.10.5 on 2017-02-17 00:51
from __future__ import unicode_literals
from django.conf import settings
@@ -25,7 +25,7 @@ class Item(models.Model):
item_owner = models.ForeignKey(Owner)
def __str__(self):
- return '{} - Disponibles:{}'.format(self.item_name, self.available_count)
+ return '{} - Disponibles:{}, Borrowed: {}'.format(self.item_name, self.available_count, self.current_borrowed)
# Each individual item (will have it's own ID and shit.)
@@ -34,7 +34,7 @@ class IndividualItem(models.Model):
is_borrowed = models.BooleanField(default=False)
def __str__(self):
- return '{}, Is Borrowed? {}!'.format(self.item.item_name, self.is_borrowed)
+ return '{} ..... ID: {}..... Borrowed={}.'.format(self.item.item_name, self.pk, self.is_borrowed)
def item_directory_path(instance, filename):
@@ -34,19 +34,23 @@ def borrow(request, pk):
raise Http404('Item no existe.') # TODO: Planning on redirecting to custom 404 page in future
else:
- # Changing item's attributes
- item.available_count -= 1
- item.current_borrowed += 1
-
- item.save()
-
- # Change the IndividualItem's isBorrowed to true
+ # Gets the first item that's not borrowed yet.
unborrowed_individual_item = item.individualitem_set.filter(is_borrowed=False)[0]
- unborrowed_individual_item.is_borrowed = False
+
+ # Change the unborrowerd to borrowed = True
+ unborrowed_individual_item.is_borrowed = True
unborrowed_individual_item.save()
# Creating new ItemBorrowed object
borrowed = ItemBorrowed(item=item, user=request.user)
borrowed.save()
+ # Changing item's attributes
+ item.available_count -= 1
+ item.current_borrowed += 1
+
+ item.save()
+
+ # TODO: validate if there are still items left to be borrowed or not.
+
return render(request, 'inventory/admin.html', {'item': item})
@@ -15,4 +15,7 @@
{% endfor %}
+ {# Temporary #}
+<a href="{% url 'inventory:index' %}">Go back to Inventory index.</a>
+
{% endblock %}

0 comments on commit c3baaaf

Please sign in to comment.