Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
Deokhyun_Lee_reading
Project
Project
Details
Activity
Releases
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
Deokhyun Lee
Deokhyun_Lee_reading
Commits
a5d1ce08
Commit
a5d1ce08
authored
Apr 25, 2023
by
Deokhyun Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renamed the model books to book (name of the models should be singular)
parent
587a7933
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
83 additions
and
20 deletions
+83
-20
admin.py
Deokhyun_Lee_reading/bookshelf/admin.py
+3
-3
forms.py
Deokhyun_Lee_reading/bookshelf/forms.py
+7
-8
0002_book_delete_books.py
...ee_reading/bookshelf/migrations/0002_book_delete_books.py
+29
-0
0003_rename_book_books.py
...ee_reading/bookshelf/migrations/0003_rename_book_books.py
+17
-0
0004_rename_books_book.py
...ee_reading/bookshelf/migrations/0004_rename_books_book.py
+17
-0
models.py
Deokhyun_Lee_reading/bookshelf/models.py
+3
-3
views.py
Deokhyun_Lee_reading/bookshelf/views.py
+7
-6
No files found.
Deokhyun_Lee_reading/bookshelf/admin.py
View file @
a5d1ce08
from
django.contrib
import
admin
from
.models
import
Author
,
Book
s
from
.models
import
Author
,
Book
# admin panel for Author model
...
...
@@ -13,12 +13,12 @@ class AuthorAdmin(admin.ModelAdmin):
# admin panel for Books model
class
BooksAdmin
(
admin
.
ModelAdmin
):
model
=
Book
s
model
=
Book
list_display
=
(
'title'
,
'author'
,
'publisher'
,
'year_published'
,
'ISBN'
,
'blurb'
)
search_fields
=
(
'title'
,
'author'
,
'publisher'
,
'year_published'
,
'ISBN'
,
'blurb'
)
list_filter
=
(
'title'
,
'author'
,
'publisher'
,
'year_published'
,
'ISBN'
,
'blurb'
)
admin
.
site
.
register
(
Author
,
AuthorAdmin
)
admin
.
site
.
register
(
Book
s
,
BooksAdmin
)
admin
.
site
.
register
(
Book
,
BooksAdmin
)
Deokhyun_Lee_reading/bookshelf/forms.py
View file @
a5d1ce08
from
django
import
forms
from
.models
import
Book
s
from
.models
import
Book
,
Author
class
AddBookForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
Books
model
=
Book
fields
=
'__all__'
class
AddAuthorForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
Author
fields
=
'__all__'
# def save(self, commit=True):
# book = super().save(commit=False)
# # Do any additional processing of the form data here
# if commit:
# book.save()
# return book
Deokhyun_Lee_reading/bookshelf/migrations/0002_book_delete_books.py
0 → 100644
View file @
a5d1ce08
# Generated by Django 4.1.7 on 2023-04-25 11:22
from
django.db
import
migrations
,
models
import
django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'bookshelf'
,
'0001_initial'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'Book'
,
fields
=
[
(
'id'
,
models
.
BigAutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'title'
,
models
.
CharField
(
max_length
=
100
)),
(
'publisher'
,
models
.
CharField
(
max_length
=
100
)),
(
'year_published'
,
models
.
DateTimeField
(
verbose_name
=
'year published'
)),
(
'ISBN'
,
models
.
CharField
(
max_length
=
13
)),
(
'blurb'
,
models
.
CharField
(
max_length
=
250
)),
(
'author'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'bookshelf.author'
)),
],
),
migrations
.
DeleteModel
(
name
=
'Books'
,
),
]
Deokhyun_Lee_reading/bookshelf/migrations/0003_rename_book_books.py
0 → 100644
View file @
a5d1ce08
# Generated by Django 4.1.7 on 2023-04-25 11:24
from
django.db
import
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'bookshelf'
,
'0002_book_delete_books'
),
]
operations
=
[
migrations
.
RenameModel
(
old_name
=
'Book'
,
new_name
=
'Books'
,
),
]
Deokhyun_Lee_reading/bookshelf/migrations/0004_rename_books_book.py
0 → 100644
View file @
a5d1ce08
# Generated by Django 4.1.7 on 2023-04-25 11:26
from
django.db
import
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'bookshelf'
,
'0003_rename_book_books'
),
]
operations
=
[
migrations
.
RenameModel
(
old_name
=
'Books'
,
new_name
=
'Book'
,
),
]
Deokhyun_Lee_reading/bookshelf/models.py
View file @
a5d1ce08
...
...
@@ -14,12 +14,12 @@ class Author(models.Model):
return
self
.
first_name
+
" "
+
self
.
last_name
# Book
s
model
class
Book
s
(
models
.
Model
):
# Book model
class
Book
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
100
)
author
=
models
.
ForeignKey
(
Author
,
on_delete
=
models
.
CASCADE
)
publisher
=
models
.
CharField
(
max_length
=
100
)
year_published
=
models
.
DateTimeField
(
"
date
published"
)
year_published
=
models
.
DateTimeField
(
"
year
published"
)
ISBN
=
models
.
CharField
(
max_length
=
13
)
blurb
=
models
.
CharField
(
max_length
=
250
)
...
...
Deokhyun_Lee_reading/bookshelf/views.py
View file @
a5d1ce08
...
...
@@ -2,7 +2,7 @@ from django.views import View
from
django.shortcuts
import
render
,
redirect
from
django.views.generic
import
ListView
,
DetailView
,
CreateView
from
django.shortcuts
import
render
from
.models
import
Author
,
Book
s
from
.models
import
Author
,
Book
from
.forms
import
AddBookForm
# View for Home (landing page)
...
...
@@ -27,23 +27,23 @@ class AuthorDetailView(DetailView):
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
()
.
get_context_data
(
**
kwargs
)
# get by self == Author's id to get Book's foreign key that matches up.
context
[
'books'
]
=
Book
s
.
objects
.
filter
(
author
=
self
.
object
)
context
[
'books'
]
=
Book
.
objects
.
filter
(
author
=
self
.
object
)
return
context
# Views for Books page
class
BookListView
(
ListView
):
model
=
Book
s
model
=
Book
template_name
=
'books/books.html'
context_object_name
=
'books'
ordering
=
[
'id'
]
class
BookDetailView
(
DetailView
):
model
=
Book
s
model
=
Book
template_name
=
'books/book_details.html'
context_object_name
=
'book'
class
BookAddListView
(
CreateView
):
model
=
Book
s
model
=
Book
fields
=
'__all__'
template_name
=
"books/add-book.html"
...
...
@@ -55,4 +55,5 @@ class BookAddListView(CreateView):
# pass the pk and redirect.
return
redirect
(
'book_detail'
,
pk
=
new_book
.
pk
)
else
:
return
render
(
request
,
'book_details.html'
,
{
'form'
:
form
})
\ No newline at end of file
return
render
(
request
,
'book_details.html'
,
{
'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