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
51b012d8
Commit
51b012d8
authored
Jul 05, 2024
by
impfundev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: cascade relations
parent
05aadb7b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
73 additions
and
6 deletions
+73
-6
0005_alter_bookloans_book_alter_bookloans_librarians_and_more.py
...ter_bookloans_book_alter_bookloans_librarians_and_more.py
+32
-0
models.py
book_loans/models.py
+3
-3
book_loan_delete_form.html
book_loans/templates/book_loan_delete_form.html
+1
-1
loans.html
book_loans/templates/loans.html
+0
-1
views.py
book_loans/views.py
+19
-1
0006_alter_members_account_number.py
members/migrations/0006_alter_members_account_number.py
+18
-0
No files found.
book_loans/migrations/0005_alter_bookloans_book_alter_bookloans_librarians_and_more.py
0 → 100644
View file @
51b012d8
# Generated by Django 5.0.6 on 2024-07-05 02:14
import
django.db.models.deletion
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'book_loans'
,
'0004_alter_bookloans_return_date'
),
(
'books'
,
'0002_book_stock'
),
(
'librarians'
,
'0003_alter_loginhistory_table'
),
(
'members'
,
'0006_alter_members_account_number'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'bookloans'
,
name
=
'book'
,
field
=
models
.
ForeignKey
(
null
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'books.book'
),
),
migrations
.
AlterField
(
model_name
=
'bookloans'
,
name
=
'librarians'
,
field
=
models
.
ForeignKey
(
null
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'librarians.librarians'
),
),
migrations
.
AlterField
(
model_name
=
'bookloans'
,
name
=
'member'
,
field
=
models
.
ForeignKey
(
null
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'members.members'
),
),
]
book_loans/models.py
View file @
51b012d8
...
...
@@ -5,9 +5,9 @@ from librarians.models import Librarians
class
BookLoans
(
models
.
Model
):
book
=
models
.
ForeignKey
(
to
=
Book
,
on_delete
=
models
.
SET_NULL
,
null
=
True
)
member
=
models
.
ForeignKey
(
to
=
Members
,
on_delete
=
models
.
SET_NULL
,
null
=
True
)
librarians
=
models
.
ForeignKey
(
to
=
Librarians
,
on_delete
=
models
.
SET_NULL
,
null
=
True
)
book
=
models
.
ForeignKey
(
to
=
Book
,
on_delete
=
models
.
CASCADE
,
null
=
True
)
member
=
models
.
ForeignKey
(
to
=
Members
,
on_delete
=
models
.
CASCADE
,
null
=
True
)
librarians
=
models
.
ForeignKey
(
to
=
Librarians
,
on_delete
=
models
.
CASCADE
,
null
=
True
)
notes
=
models
.
TextField
(
blank
=
True
,
null
=
True
)
loan_date
=
models
.
DateTimeField
()
due_date
=
models
.
DateTimeField
()
...
...
book_loans/templates/book_loan_delete_form.html
View file @
51b012d8
...
...
@@ -24,7 +24,7 @@
</div>
<div
class=
"modal-body"
>
Once data is deleted, it cannot be restored.
<input
type=
"hidden"
name=
"
id"
id=
"almacen_id
"
/>
<input
type=
"hidden"
name=
"
book_id"
id=
"almacen_id"
value=
"{{ book_loan.book_id }}
"
/>
</div>
<div
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-secondary"
data-bs-dismiss=
"modal"
>
...
...
book_loans/templates/loans.html
View file @
51b012d8
...
...
@@ -11,7 +11,6 @@
>
<i
class=
"bi bi-plus-circle"
></i>
Add Book Loan
</button>
{% include "search_form.html" %}
</div>
{% include "book_loan_table_data.html" %}
</div>
...
...
book_loans/views.py
View file @
51b012d8
...
...
@@ -51,7 +51,7 @@ def index(request):
)
if
request
.
method
==
"GET"
:
query
=
request
.
GET
.
get
(
"q"
)
#
query = request.GET.get("q")
order
=
request
.
GET
.
get
(
"o"
)
# if query is not None:
...
...
@@ -113,6 +113,14 @@ def update(request, id):
notes
=
notes
,
updated_at
=
datetime
.
now
(),
)
updated_loan
=
BookLoans
.
objects
.
get
(
id
=
id
)
book
=
Book
.
objects
.
get
(
id
=
book_id
)
new_stock
=
book
.
stock
+
1
if
updated_loan
.
return_date
is
not
None
and
book
.
stock
<
new_stock
:
Book
.
objects
.
filter
(
id
=
book_id
)
.
update
(
stock_in
=
new_stock
)
return
HttpResponseRedirect
(
"/dashboard/book-loans"
)
context
[
"form"
]
=
form
...
...
@@ -124,7 +132,17 @@ def delete(request, id):
book_loan
=
get_object_or_404
(
BookLoans
,
id
=
id
)
if
request
.
method
==
"POST"
:
books
=
Book
.
objects
.
all
()
book_id
=
request
.
POST
[
"book_id"
]
book
=
Book
.
objects
.
get
(
id
=
book_id
)
new_stock
=
book
.
stock
+
1
if
book_loan
.
return_date
is
None
:
books
.
filter
(
id
=
book_id
)
.
update
(
stock
=
new_stock
)
book_loan
.
delete
()
return
HttpResponseRedirect
(
"/dashboard/book-loans"
)
return
render
(
request
,
"loans.html"
,
context
)
members/migrations/0006_alter_members_account_number.py
0 → 100644
View file @
51b012d8
# Generated by Django 5.0.6 on 2024-07-05 02:14
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'members'
,
'0005_alter_members_account_number'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'members'
,
name
=
'account_number'
,
field
=
models
.
CharField
(
default
=
'810779514016329'
,
editable
=
False
,
max_length
=
15
),
),
]
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