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

fix: remaining loan

parent 3cc51702
......@@ -34,6 +34,11 @@ class OverduedLoanView(ListView):
return queryset
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["now"] = timezone.now()
return context
class UpcomingLoanView(ListView):
model = BookLoan
......@@ -67,11 +72,13 @@ class UpcomingLoanView(ListView):
elif order == "old":
queryset = queryset.order_by("created_at")
today = timezone.now()
queryset = queryset.annotate(remaining_loan_time=(F("due_date") - today))
return queryset
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["now"] = timezone.now()
return context
class HomePage(TemplateView):
template_name = "homepage.html"
......
......@@ -15,11 +15,9 @@
<tr>
<td>{{ loan.book.title }}</td>
<td>{{ loan.member.user.username }}</td>
{% if loan.remaining_loan_time %}
<td>
{{ loan.remaining_loan_time.days }} days left
{{ loan.due_date|timeuntil:now }} left
</td>
{% endif %}
<td>{{ loan.loan_date }}</td>
<td>{{ loan.due_date }}</td>
<td>{{ loan.return_date }}</td>
......
......@@ -32,6 +32,11 @@ class BookLoanListView(generic.ListView):
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):
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