Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
janang_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
Jan Ericsson Ong Ang
janang_reading
Commits
a114bab8
Commit
a114bab8
authored
Mar 30, 2023
by
Jan Ericsson Ong Ang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed details for books and authors
parent
b9e8b471
Pipeline
#3116
failed with stages
Changes
11
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
38 additions
and
23 deletions
+38
-23
models.cpython-310.pyc
janang_reading/bookshelf/__pycache__/models.cpython-310.pyc
+0
-0
urls.cpython-310.pyc
janang_reading/bookshelf/__pycache__/urls.cpython-310.pyc
+0
-0
views.cpython-310.pyc
janang_reading/bookshelf/__pycache__/views.cpython-310.pyc
+0
-0
0001_initial.cpython-310.pyc
...shelf/migrations/__pycache__/0001_initial.cpython-310.pyc
+0
-0
models.py
janang_reading/bookshelf/models.py
+13
-7
author_details.html
...reading/bookshelf/templates/bookshelf/author_details.html
+6
-1
authors.html
janang_reading/bookshelf/templates/bookshelf/authors.html
+1
-1
book_details.html
...g_reading/bookshelf/templates/bookshelf/book_details.html
+3
-3
books.html
janang_reading/bookshelf/templates/bookshelf/books.html
+2
-3
urls.py
janang_reading/bookshelf/urls.py
+2
-2
views.py
janang_reading/bookshelf/views.py
+11
-6
No files found.
janang_reading/bookshelf/__pycache__/models.cpython-310.pyc
View file @
a114bab8
No preview for this file type
janang_reading/bookshelf/__pycache__/urls.cpython-310.pyc
View file @
a114bab8
No preview for this file type
janang_reading/bookshelf/__pycache__/views.cpython-310.pyc
View file @
a114bab8
No preview for this file type
janang_reading/bookshelf/migrations/__pycache__/0001_initial.cpython-310.pyc
View file @
a114bab8
No preview for this file type
janang_reading/bookshelf/models.py
View file @
a114bab8
...
@@ -2,22 +2,28 @@ from django.db import models
...
@@ -2,22 +2,28 @@ from django.db import models
# Create your models here.
# Create your models here.
class
Author
(
models
.
Model
):
class
Author
(
models
.
Model
):
first_name
=
models
.
CharField
(
max_length
=
50
,
default
=
""
)
first_name
=
models
.
CharField
(
max_length
=
50
)
last_name
=
models
.
CharField
(
max_length
=
50
,
default
=
""
)
last_name
=
models
.
CharField
(
max_length
=
50
)
age
=
models
.
IntegerField
(
default
=
0
)
age
=
models
.
IntegerField
(
default
=
0
)
nationality
=
models
.
CharField
(
max_length
=
50
,
default
=
""
)
nationality
=
models
.
CharField
(
max_length
=
50
)
bio
=
models
.
TextField
(
max_length
=
700
,
default
=
""
)
bio
=
models
.
TextField
(
max_length
=
700
)
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
first_name
+
" "
+
self
.
last_name
return
self
.
first_name
+
" "
+
self
.
last_name
def
get_absolute_url
(
self
):
return
reverse
(
'product_change'
,
kwargs
=
{
'id'
:
self
.
id
})
#https://stackoverflow.com/questions/70442828/django-object-list-from-listview-with-two-models%20#}%20{%%20for%20object%20in%20author.books_set.all
# for absolute url and _set_all
class
Books
(
models
.
Model
):
class
Books
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
50
,
default
=
""
)
title
=
models
.
CharField
(
max_length
=
50
)
author
=
models
.
ForeignKey
(
Author
,
on_delete
=
models
.
CASCADE
)
author
=
models
.
ForeignKey
(
Author
,
on_delete
=
models
.
CASCADE
)
publisher
=
models
.
CharField
(
max_length
=
50
,
default
=
""
)
publisher
=
models
.
CharField
(
max_length
=
50
)
year_published
=
models
.
IntegerField
(
default
=
0
)
year_published
=
models
.
IntegerField
(
default
=
0
)
ISBN
=
models
.
IntegerField
(
default
=
0
)
ISBN
=
models
.
IntegerField
(
default
=
0
)
blurb
=
models
.
TextField
(
default
=
""
)
blurb
=
models
.
TextField
(
max_length
=
10000
)
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
title
return
self
.
title
\ No newline at end of file
janang_reading/bookshelf/templates/bookshelf/author_details.html
View file @
a114bab8
...
@@ -10,7 +10,12 @@
...
@@ -10,7 +10,12 @@
<p>
{{ author.bio }}
</p>
<p>
{{ author.bio }}
</p>
<p>
Books by {{ author.first_name }} {{ author.last_name }} I love
</p>
<p>
Books by {{ author.first_name }} {{ author.last_name }} I love
</p>
<a
href=
"/bookshelf/books/<int:pk>/details/"
>
Home
</a><br>
{% for authbook in author.books_set.all %}
<a
href=
"/bookshelf/authors/{{ authbook.id }}/details/"
>
{{ authbook }}
<br></a>
{% endfor %}
<br>
<a
href=
"/bookshelf/"
>
Home
</a>
<a
href=
"/bookshelf/"
>
Home
</a>
<a
href=
"/bookshelf/books/"
>
Books
</a>
<a
href=
"/bookshelf/books/"
>
Books
</a>
...
...
janang_reading/bookshelf/templates/bookshelf/authors.html
View file @
a114bab8
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
<br>
<br>
{% for author in author_data %}
{% for author in author_data %}
<a
href=
"/bookshelf/authors/{{ author.
pk
}}/details/"
>
{{ author.first_name }} {{ author.last_name }}
</a>
<a
href=
"/bookshelf/authors/{{ author.
id
}}/details/"
>
{{ author.first_name }} {{ author.last_name }}
</a>
<br>
<br>
{% endfor %}
{% endfor %}
<br>
<br>
...
...
janang_reading/bookshelf/templates/bookshelf/book_details.html
View file @
a114bab8
...
@@ -5,11 +5,11 @@
...
@@ -5,11 +5,11 @@
{% block content %}
{% block content %}
{% block header %}
<h1>
{{ books.title }}
</h1>
{% endblock %}
{% block header %}
<h1>
{{ books.title }}
</h1>
{% endblock %}
<a
href=
"/bookshelf/authors/{{
books.author.pk }}/details/"
>
{{ books.author.pk
}}
</a><br>
<a
href=
"/bookshelf/authors/{{
author.books.id }}/details/"
>
{{ books.author
}}
</a><br>
<p>
{{ books.publisher }}
</p>
<p>
{{ books.publisher }}
</p>
<p>
{{ books.year_published }}
</p>
<p>
{{ books.year_published }}
</p>
<p>
{{ books.
year_
ISBN }}
</p>
<p>
{{ books.ISBN }}
</p>
<p>
{{ books.
year_
blurb }}
</p>
<p>
{{ books.blurb }}
</p>
<a
href=
"/bookshelf/"
>
Home
</a>
<a
href=
"/bookshelf/"
>
Home
</a>
<a
href=
"/bookshelf/books/"
>
Books
</a>
<a
href=
"/bookshelf/books/"
>
Books
</a>
...
...
janang_reading/bookshelf/templates/bookshelf/books.html
View file @
a114bab8
...
@@ -6,9 +6,8 @@
...
@@ -6,9 +6,8 @@
{% block header %}
<h1>
{{ nickname }}'s Favorite Books:
</h1>
{% endblock %}
{% block header %}
<h1>
{{ nickname }}'s Favorite Books:
</h1>
{% endblock %}
<br>
{% for book in book_data %}
{% for book in book_data %}
<a
href=
"/bookshelf/books/{{ book.
pk
}}/details/"
>
{{ book.title }}
</a>
<a
href=
"/bookshelf/books/{{ book.
id
}}/details/"
>
{{ book.title }}
</a>
<br>
<br>
{% endfor %}
{% endfor %}
<br>
<br>
...
...
janang_reading/bookshelf/urls.py
View file @
a114bab8
...
@@ -7,9 +7,9 @@ from .views import HomeView, AuthorView, AuthorDetailView, BooksView, BookDetail
...
@@ -7,9 +7,9 @@ from .views import HomeView, AuthorView, AuthorDetailView, BooksView, BookDetail
urlpatterns
=
[
urlpatterns
=
[
path
(
''
,
views
.
HomeView
,
name
=
'home'
),
path
(
''
,
views
.
HomeView
,
name
=
'home'
),
path
(
'authors/'
,
AuthorView
.
as_view
(),
name
=
'authors'
),
path
(
'authors/'
,
AuthorView
.
as_view
(),
name
=
'authors'
),
path
(
'authors/<int:
pk
>/details/'
,
AuthorDetailView
.
as_view
(),
name
=
'author-detail'
),
path
(
'authors/<int:
id
>/details/'
,
AuthorDetailView
.
as_view
(),
name
=
'author-detail'
),
path
(
'books/'
,
BooksView
.
as_view
(),
name
=
'books'
),
path
(
'books/'
,
BooksView
.
as_view
(),
name
=
'books'
),
path
(
'books/<int:
pk
>/details/'
,
BookDetailView
.
as_view
(),
name
=
'books-detail'
),
path
(
'books/<int:
id
>/details/'
,
BookDetailView
.
as_view
(),
name
=
'books-detail'
),
]
]
app_name
=
'bookshelf'
app_name
=
'bookshelf'
\ No newline at end of file
janang_reading/bookshelf/views.py
View file @
a114bab8
...
@@ -10,24 +10,29 @@ def HomeView(request):
...
@@ -10,24 +10,29 @@ def HomeView(request):
return
render
(
request
,
'bookshelf/home.html'
,
{
'nickname'
:
'Jan'
})
return
render
(
request
,
'bookshelf/home.html'
,
{
'nickname'
:
'Jan'
})
class
AuthorView
(
ListView
):
class
AuthorView
(
ListView
):
def
get
(
self
,
request
):
model
=
Author
model
=
Author
queryset
=
Author
.
objects
.
all
()
def
get
(
self
,
request
):
author_data
=
Author
.
objects
.
all
()
.
values
()
author_data
=
Author
.
objects
.
all
()
.
values
()
return
render
(
request
,
'bookshelf/authors.html'
,
{
'nickname'
:
'Jan'
,
'author_data'
:
author_data
})
return
render
(
request
,
'bookshelf/authors.html'
,
{
'nickname'
:
'Jan'
,
'author_data'
:
author_data
})
class
AuthorDetailView
(
DetailView
):
class
AuthorDetailView
(
DetailView
):
pk_url_kwarg
=
'id'
model
=
Author
model
=
Author
model_data
=
Author
queryset
=
Author
.
objects
.
all
()
template_name
=
'bookshelf/author_details.html'
template_name
=
'bookshelf/author_details.html'
context_object_name
=
'author'
class
BooksView
(
ListView
):
class
BooksView
(
ListView
):
def
get
(
self
,
request
):
model
=
Books
model
=
Books
queryset
=
Books
.
objects
.
all
()
def
get
(
self
,
request
):
book_data
=
Books
.
objects
.
all
()
.
values
()
book_data
=
Books
.
objects
.
all
()
.
values
()
return
render
(
request
,
'bookshelf/books.html'
,
{
'nickname'
:
'Jan'
,
'book_data'
:
book_data
})
return
render
(
request
,
'bookshelf/books.html'
,
{
'nickname'
:
'Jan'
,
'book_data'
:
book_data
})
class
BookDetailView
(
DetailView
):
class
BookDetailView
(
DetailView
):
pk_url_kwarg
=
'id'
model
=
Books
model
=
Books
model_data
=
Books
queryset
=
Books
.
objects
.
all
()
template_name
=
'bookshelf/books_details.html'
template_name
=
'bookshelf/book_details.html'
\ No newline at end of file
context_object_name
=
'books'
\ No newline at end of file
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