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
7f25fe9d
Commit
7f25fe9d
authored
Jul 03, 2024
by
impfundev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: stock book
parent
688b1650
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
3 deletions
+49
-3
views.py
book_loans/views.py
+5
-0
forms.py
books/forms.py
+9
-0
0002_book_stock.py
books/migrations/0002_book_stock.py
+18
-0
models.py
books/models.py
+1
-0
book_table_data.html
books/templates/book_table_data.html
+2
-0
views.py
books/views.py
+14
-3
No files found.
book_loans/views.py
View file @
7f25fe9d
...
...
@@ -29,6 +29,10 @@ def index(request):
return_date
=
form
.
data
[
"return_date"
]
or
None
notes
=
form
.
data
[
"notes"
]
book
=
books
.
get
(
id
=
book_id
)
new_stock
=
book
.
stock
-
1
books
.
filter
(
id
=
book_id
)
.
update
(
stock
=
new_stock
)
auth_session
=
request
.
session
.
get
(
"auth_session"
,
None
)
decoded
=
jwt
.
decode
(
auth_session
,
settings
.
JWT_SECRET
,
algorithms
=
[
"HS256"
]
...
...
@@ -75,6 +79,7 @@ def update(request, id):
auth_session
=
request
.
session
.
get
(
"auth_session"
,
None
)
decoded
=
jwt
.
decode
(
auth_session
,
settings
.
JWT_SECRET
,
algorithms
=
[
"HS256"
])
librarians_id
=
decoded
[
"librarian_id"
]
context
[
"initial_book_id"
]
=
book_id
if
form
.
is_valid
:
loan_date
=
form
.
data
[
"loan_date"
]
...
...
books/forms.py
View file @
7f25fe9d
...
...
@@ -11,6 +11,15 @@ class BookForm(forms.Form):
}
),
)
stock
=
forms
.
IntegerField
(
widget
=
forms
.
TextInput
(
attrs
=
{
"type"
:
"number"
,
"placeholder"
:
"Stock"
,
"class"
:
"form-control"
,
}
),
)
description
=
forms
.
CharField
(
max_length
=
255
,
widget
=
forms
.
Textarea
(
...
...
books/migrations/0002_book_stock.py
0 → 100644
View file @
7f25fe9d
# Generated by Django 4.2 on 2024-07-03 08:13
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'books'
,
'0001_initial'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'book'
,
name
=
'stock'
,
field
=
models
.
BigIntegerField
(
blank
=
True
,
null
=
True
),
),
]
books/models.py
View file @
7f25fe9d
...
...
@@ -4,6 +4,7 @@ from django.db import models
class
Book
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
100
)
description
=
models
.
CharField
(
max_length
=
255
)
stock
=
models
.
BigIntegerField
(
blank
=
True
,
null
=
True
)
created_at
=
models
.
DateTimeField
(
auto_now_add
=
True
)
updated_at
=
models
.
DateTimeField
(
auto_now
=
True
)
...
...
books/templates/book_table_data.html
View file @
7f25fe9d
...
...
@@ -2,6 +2,7 @@
<thead>
<tr
class=
"table-primary"
>
<th
scope=
"col"
>
Title
</th>
<th
scope=
"col"
>
Stock
</th>
<th
scope=
"col"
>
Description
</th>
<th
scope=
"col"
>
Created At
</th>
<th
scope=
"col"
>
Updated At
</th>
...
...
@@ -12,6 +13,7 @@
{% if books %} {% for book in books %}
<tr>
<td>
{{ book.title }}
</td>
<td>
{{ book.stock }}
</td>
<td>
{{ book.description }}
</td>
<td>
{{ book.created_at }}
</td>
<td>
{{ book.updated_at }}
</td>
...
...
books/views.py
View file @
7f25fe9d
...
...
@@ -14,9 +14,10 @@ def index(request):
form
=
BookForm
(
request
.
POST
)
if
form
.
is_valid
:
title
=
form
.
data
[
"title"
]
stock
=
form
.
data
[
"stock"
]
description
=
form
.
data
[
"description"
]
Book
.
objects
.
create
(
title
=
title
,
description
=
description
)
Book
.
objects
.
create
(
title
=
title
,
stock
=
stock
,
description
=
description
)
return
render
(
request
,
"book.html"
,
context
)
...
...
@@ -25,17 +26,27 @@ def update(request, id):
latest_book_list
=
Book
.
objects
.
order_by
(
"created_at"
)[:
10
]
context
=
{
"books"
:
latest_book_list
}
book
=
Book
.
objects
.
get
(
id
=
id
)
initial_dict
=
{
"title"
:
book
.
title
,
"description"
:
book
.
description
}
initial_dict
=
{
"title"
:
book
.
title
,
"stock"
:
book
.
stock
,
"description"
:
book
.
description
,
}
print
(
book
.
title
)
form
=
BookForm
(
request
.
POST
or
None
,
initial
=
initial_dict
)
if
request
.
method
==
"POST"
:
if
form
.
is_valid
:
title
=
form
.
data
[
"title"
]
stock
=
form
.
data
[
"stock"
]
description
=
form
.
data
[
"description"
]
book
=
Book
.
objects
.
filter
(
id
=
id
)
book
.
update
(
title
=
title
,
description
=
description
,
updated_at
=
datetime
.
now
())
book
.
update
(
title
=
title
,
stock
=
stock
,
description
=
description
,
updated_at
=
datetime
.
now
(),
)
return
HttpResponseRedirect
(
"/dashboard/books"
)
context
[
"form"
]
=
form
...
...
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