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
be913327
Commit
be913327
authored
Jul 15, 2024
by
Ilham Maulana
💻
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: rrefactor
parent
977acecd
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
31 deletions
+22
-31
forms.py
book/forms.py
+13
-28
book_detail.html
book/templates/book_detail.html
+9
-3
No files found.
book/forms.py
View file @
be913327
from
django
import
forms
from
django
import
forms
from
.models
import
Book
from
.models
import
Book
"""
title = models.CharField(max_length=150)
author = models.CharField(max_length=50)
publish_date = models.DateTimeField()
rating = models.IntegerField(
default=0, validators=[MaxValueValidator(5), MinValueValidator(0)]
)
isbn = models.CharField(max_length=15, default="xxxxxxxxx-x")
description = models.CharField(max_length=255, blank=True, null=True)
cover_image = models.ImageField(upload_to="uploads", blank=True, null=True)
category = models.ManyToManyField(Category, blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
"""
class
BookForm
(
forms
.
ModelForm
):
class
BookForm
(
forms
.
ModelForm
):
class
Meta
:
class
Meta
:
...
@@ -23,12 +8,6 @@ class BookForm(forms.ModelForm):
...
@@ -23,12 +8,6 @@ class BookForm(forms.ModelForm):
fields
=
"__all__"
fields
=
"__all__"
widgets
=
{
widgets
=
{
"cover_image"
:
forms
.
FileInput
(
attrs
=
{
"placeholder"
:
"Cover Image"
,
"class"
:
"form-control"
,
}
),
"title"
:
forms
.
TextInput
(
"title"
:
forms
.
TextInput
(
attrs
=
{
attrs
=
{
"placeholder"
:
"Title"
,
"placeholder"
:
"Title"
,
...
@@ -41,16 +20,21 @@ class BookForm(forms.ModelForm):
...
@@ -41,16 +20,21 @@ class BookForm(forms.ModelForm):
"class"
:
"form-control"
,
"class"
:
"form-control"
,
}
}
),
),
"publish_date"
:
forms
.
TextInput
(
attrs
=
{
"type"
:
"datetime-local"
,
"class"
:
"form-control"
,
}
),
"isbn"
:
forms
.
TextInput
(
"isbn"
:
forms
.
TextInput
(
attrs
=
{
attrs
=
{
"placeholder"
:
"ISBN"
,
"placeholder"
:
"ISBN"
,
"class"
:
"form-control"
,
"class"
:
"form-control"
,
}
}
),
),
"
rating"
:
forms
.
Text
Input
(
"
cover_image"
:
forms
.
File
Input
(
attrs
=
{
attrs
=
{
"type"
:
"number"
,
"placeholder"
:
"Cover Image"
,
"placeholder"
:
"Rating"
,
"class"
:
"form-control"
,
"class"
:
"form-control"
,
}
}
),
),
...
@@ -59,15 +43,16 @@ class BookForm(forms.ModelForm):
...
@@ -59,15 +43,16 @@ class BookForm(forms.ModelForm):
"class"
:
"form-control"
,
"class"
:
"form-control"
,
}
}
),
),
"
description"
:
forms
.
Textarea
(
"
rating"
:
forms
.
TextInput
(
attrs
=
{
attrs
=
{
"placeholder"
:
"Description"
,
"type"
:
"number"
,
"placeholder"
:
"Rating"
,
"class"
:
"form-control"
,
"class"
:
"form-control"
,
}
}
),
),
"
publish_date"
:
forms
.
TextInput
(
"
description"
:
forms
.
Textarea
(
attrs
=
{
attrs
=
{
"
type"
:
"number
"
,
"
placeholder"
:
"Description
"
,
"class"
:
"form-control"
,
"class"
:
"form-control"
,
}
}
),
),
...
...
book/templates/book_detail.html
View file @
be913327
...
@@ -20,9 +20,15 @@
...
@@ -20,9 +20,15 @@
/>
/>
<div
class=
"col"
>
<div
class=
"col"
>
<h1
class=
"h2 row"
>
{{ book.title }}
</h1>
<h1
class=
"h2 row"
>
{{ book.title }}
</h1>
<p
class=
"h5 row"
>
{{ book.description }}
</p>
<p
class=
"h5 row"
>
Stock: {{ book.stock }}
</p>
<div
class=
"row d-flex flex-collumn gap-2"
>
<p
class=
"row badge text-bg-secondary"
>
{{ book.category.name }}
</p>
<span
class=
"row"
>
Author: {{ book.author }}
</span>
<span
class=
"row"
>
Rating: {{ book.rating }}
</span>
<time
class=
"row"
>
Published Date: {{ book.publish_date }}
</time>
<div/>
<p
class=
"fs-5 row text-secondary"
>
{{ book.description }}
</p>
<p
class=
"row badge text-bg-secondary"
>
{% if book.category.name is None %}uncategories {% else %}{{book.category.name}}{% endif %}
</p>
<time
datetime=
"{{ book.created_at }}"
class=
"row fs-6"
<time
datetime=
"{{ book.created_at }}"
class=
"row fs-6"
>
Created at: {{ book.created_at }}
</time
>
Created at: {{ book.created_at }}
</time
>
>
...
...
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