Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
library-app-django
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ilham Maulana
library-app-django
Commits
a61ee99f
Commit
a61ee99f
authored
Jul 19, 2024
by
Ilham Maulana
💻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: remaining loan time
parent
b6a6e122
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
1 deletion
+15
-1
views.py
dashboard/views.py
+4
-1
book_loan_table_data.html
loans/templates/book_loan_table_data.html
+6
-0
views.py
loans/views.py
+5
-0
No files found.
dashboard/views.py
View file @
a61ee99f
from
django.utils
import
timezone
from
django.db.models
import
Q
from
django.db.models
import
Q
,
F
from
django.views.generic
import
ListView
,
TemplateView
from
loans.models
import
BookLoan
...
...
@@ -67,6 +67,9 @@ 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
...
...
loans/templates/book_loan_table_data.html
View file @
a61ee99f
...
...
@@ -3,6 +3,7 @@
<tr
class=
"table-primary"
>
<th
scope=
"col"
>
Book
</th>
<th
scope=
"col"
>
Member
</th>
<th
scope=
"col"
>
Remaining Loan
</th>
<th
scope=
"col"
>
Loan Date
</th>
<th
scope=
"col"
>
Due Date
</th>
<th
scope=
"col"
>
Return Date
</th>
...
...
@@ -14,6 +15,11 @@
<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
</td>
{% endif %}
<td>
{{ loan.loan_date }}
</td>
<td>
{{ loan.due_date }}
</td>
<td>
{{ loan.return_date }}
</td>
...
...
loans/views.py
View file @
a61ee99f
from
django.db.models
import
F
from
django.utils
import
timezone
from
django.db.models
import
Q
from
django.views
import
generic
from
.models
import
BookLoan
...
...
@@ -25,6 +27,9 @@ class BookLoanListView(generic.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
.
order_by
(
"-created_at"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment