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
a3af8e9b
Commit
a3af8e9b
authored
Jul 09, 2024
by
impfundev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: book relation to category
parent
c2f59edd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
1 deletion
+32
-1
forms.py
books/forms.py
+6
-1
0003_book_category.py
books/migrations/0003_book_category.py
+20
-0
models.py
books/models.py
+4
-0
book_table_data.html
books/templates/book_table_data.html
+2
-0
No files found.
books/forms.py
View file @
a3af8e9b
...
...
@@ -5,7 +5,7 @@ from books.models import Book
class
BookForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
Book
fields
=
[
"title"
,
"stock"
,
"description"
]
fields
=
[
"title"
,
"stock"
,
"
category"
,
"
description"
]
widgets
=
{
"title"
:
forms
.
TextInput
(
...
...
@@ -21,6 +21,11 @@ class BookForm(forms.ModelForm):
"class"
:
"form-control"
,
}
),
"category"
:
forms
.
Select
(
attrs
=
{
"class"
:
"form-control"
,
}
),
"description"
:
forms
.
Textarea
(
attrs
=
{
"placeholder"
:
"Description"
,
...
...
books/migrations/0003_book_category.py
0 → 100644
View file @
a3af8e9b
# Generated by Django 5.0.6 on 2024-07-09 12:03
import
django.db.models.deletion
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'books'
,
'0002_book_stock'
),
(
'categories'
,
'0001_initial'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'book'
,
name
=
'category'
,
field
=
models
.
ForeignKey
(
blank
=
True
,
null
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'categories.category'
),
),
]
books/models.py
View file @
a3af8e9b
from
django.db
import
models
from
categories.models
import
Category
class
Book
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
100
)
description
=
models
.
CharField
(
max_length
=
255
)
stock
=
models
.
BigIntegerField
(
blank
=
True
,
null
=
True
)
category
=
models
.
ForeignKey
(
to
=
Category
,
on_delete
=
models
.
CASCADE
,
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 @
a3af8e9b
...
...
@@ -2,6 +2,7 @@
<thead>
<tr
class=
"table-primary"
>
<th
scope=
"col"
>
Title
</th>
<th
scope=
"col"
>
Category
</th>
<th
scope=
"col"
>
Stock
</th>
<th
scope=
"col"
>
Description
</th>
<th
scope=
"col"
>
Created At
</th>
...
...
@@ -13,6 +14,7 @@
{% if object_list %} {% for book in object_list %}
<tr>
<td>
{{ book.title }}
</td>
<td>
{{ book.category.name }}
</td>
<td>
{{ book.stock }}
</td>
<td>
{{ book.description }}
</td>
<td>
{{ book.created_at }}
</td>
...
...
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