Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
alvaalvarez_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
Angelo Alvarez
alvaalvarez_reading
Commits
be6c8b2a
Commit
be6c8b2a
authored
Mar 27, 2023
by
Angelo Alvarez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Applied DetailView to Model Books
parent
9fbb8919
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
38 additions
and
10 deletions
+38
-10
models.cpython-310.pyc
...arez_reading/bookshelf/__pycache__/models.cpython-310.pyc
+0
-0
urls.cpython-310.pyc
...lvarez_reading/bookshelf/__pycache__/urls.cpython-310.pyc
+0
-0
views.cpython-310.pyc
...varez_reading/bookshelf/__pycache__/views.cpython-310.pyc
+0
-0
models.py
alvaalvarez_reading/bookshelf/models.py
+5
-1
books_detail.html
...z_reading/bookshelf/templates/bookshelf/books_detail.html
+22
-0
books_list.html
...rez_reading/bookshelf/templates/bookshelf/books_list.html
+2
-2
home.html
alvaalvarez_reading/bookshelf/templates/bookshelf/home.html
+0
-0
urls.py
alvaalvarez_reading/bookshelf/urls.py
+4
-2
views.py
alvaalvarez_reading/bookshelf/views.py
+5
-5
No files found.
alvaalvarez_reading/bookshelf/__pycache__/models.cpython-310.pyc
View file @
be6c8b2a
No preview for this file type
alvaalvarez_reading/bookshelf/__pycache__/urls.cpython-310.pyc
View file @
be6c8b2a
No preview for this file type
alvaalvarez_reading/bookshelf/__pycache__/views.cpython-310.pyc
View file @
be6c8b2a
No preview for this file type
alvaalvarez_reading/bookshelf/models.py
View file @
be6c8b2a
from
django.db
import
models
from
django.urls
import
reverse
# Create your models here.
class
Author
(
models
.
Model
):
...
...
@@ -20,4 +21,7 @@ class Books(models.Model):
blurb
=
models
.
TextField
(
max_length
=
1000
)
def
__str__
(
self
):
return
self
.
title
\ No newline at end of file
return
self
.
title
def
get_absolute_url
(
self
):
return
reverse
(
'bookshelf:books-details'
,
kwargs
=
{
'pk'
:
self
.
pk
})
\ No newline at end of file
alvaalvarez_reading/bookshelf/templates/bookshelf/books_detail.html
0 → 100644
View file @
be6c8b2a
{% extends 'base.html' %}
{% load static %}
{% block title %}{{ object.title }}{% endblock %}
{% block content %}
<h1>
{{ object.title }}
</h1>
<em>
Author:
</em><a
href=
"{{ object.author.get_absolute_url }}"
>
{{ object.author }}
</a>
<br>
<em>
Publisher:
</em>
{{ object.publisher }}
<br>
<em>
year_published:
</em>
{{ object.year_published }}
<br>
<em>
ISBN:
</em>
{{ object.ISBN }}
<br>
{{ object.blurb }}
<hr>
<div
id=
"links"
style=
"margin: auto; text-align: center; width: 100%"
>
<a
href=
"../home/"
>
Home
</a>
<a
href=
"../books/"
>
Books
</a>
<a
href=
"../authors/"
>
Authors
</a>
</div>
{% endblock %}
alvaalvarez_reading/bookshelf/templates/
events/books
.html
→
alvaalvarez_reading/bookshelf/templates/
bookshelf/books_list
.html
View file @
be6c8b2a
...
...
@@ -5,8 +5,8 @@
{% block content %}
<h1>
Alva's Favorite Books
</h1>
<ul>
{% for
book in books
%}
<li><a
href=
"{{
book.get_absolute_url }}"
>
{{ book
.title }}
</a></li>
{% for
object in object_list
%}
<li><a
href=
"{{
object.get_absolute_url }}"
>
{{ object
.title }}
</a></li>
{% endfor %}
</ul>
...
...
alvaalvarez_reading/bookshelf/templates/
events
/home.html
→
alvaalvarez_reading/bookshelf/templates/
bookshelf
/home.html
View file @
be6c8b2a
File moved
alvaalvarez_reading/bookshelf/urls.py
View file @
be6c8b2a
from
django.urls
import
path
from
.views
import
home
,
BooksListView
from
.views
import
home
,
BooksListView
,
BooksDetailView
urlpatterns
=
[
path
(
'home/'
,
home
,
name
=
'home'
),
path
(
'books/'
,
BooksListView
.
as_view
(),
name
=
'books'
)
path
(
'books/'
,
BooksListView
.
as_view
(),
name
=
'books-list'
),
path
(
'books/<int:pk>/details/'
,
BooksDetailView
.
as_view
(),
name
=
'books-details'
)
]
# This might be needed, depending on your Django version
...
...
alvaalvarez_reading/bookshelf/views.py
View file @
be6c8b2a
...
...
@@ -7,11 +7,11 @@ from .models import Books
# Create your views here.
def
home
(
request
):
return
render
(
request
,
'
events/
home.html'
)
return
render
(
request
,
'home.html'
)
class
BooksListView
(
View
):
class
BooksListView
(
List
View
):
model
=
Books
def
get
(
self
,
request
):
booklist
=
Books
.
objects
.
all
()
return
render
(
request
,
'events/books.html'
,
{
'books'
:
booklist
})
\ No newline at end of file
class
BooksDetailView
(
DetailView
):
model
=
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