Commit c448901d authored by Ilham Maulana's avatar Ilham Maulana 💻

fix: remaining loan

parent 3cc51702
...@@ -34,6 +34,11 @@ class OverduedLoanView(ListView): ...@@ -34,6 +34,11 @@ class OverduedLoanView(ListView):
return queryset return queryset
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["now"] = timezone.now()
return context
class UpcomingLoanView(ListView): class UpcomingLoanView(ListView):
model = BookLoan model = BookLoan
...@@ -67,11 +72,13 @@ class UpcomingLoanView(ListView): ...@@ -67,11 +72,13 @@ class UpcomingLoanView(ListView):
elif order == "old": elif order == "old":
queryset = queryset.order_by("created_at") queryset = queryset.order_by("created_at")
today = timezone.now()
queryset = queryset.annotate(remaining_loan_time=(F("due_date") - today))
return queryset return queryset
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["now"] = timezone.now()
return context
class HomePage(TemplateView): class HomePage(TemplateView):
template_name = "homepage.html" template_name = "homepage.html"
......
...@@ -15,11 +15,9 @@ ...@@ -15,11 +15,9 @@
<tr> <tr>
<td>{{ loan.book.title }}</td> <td>{{ loan.book.title }}</td>
<td>{{ loan.member.user.username }}</td> <td>{{ loan.member.user.username }}</td>
{% if loan.remaining_loan_time %}
<td> <td>
{{ loan.remaining_loan_time.days }} days left {{ loan.due_date|timeuntil:now }} left
</td> </td>
{% endif %}
<td>{{ loan.loan_date }}</td> <td>{{ loan.loan_date }}</td>
<td>{{ loan.due_date }}</td> <td>{{ loan.due_date }}</td>
<td>{{ loan.return_date }}</td> <td>{{ loan.return_date }}</td>
......
...@@ -32,6 +32,11 @@ class BookLoanListView(generic.ListView): ...@@ -32,6 +32,11 @@ class BookLoanListView(generic.ListView):
return queryset.order_by("-created_at") return queryset.order_by("-created_at")
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["now"] = timezone.now()
return context
class BookLoanCreateView(generic.edit.CreateView): class BookLoanCreateView(generic.edit.CreateView):
model = BookLoan model = BookLoan
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment