Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
addysalto_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
Mary Adelaide A. Salto
addysalto_reading
Commits
0d147dce
Commit
0d147dce
authored
Mar 28, 2023
by
Mary Adelaide A. Salto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finalized and updated to implement the web pages
parent
27be1865
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
84 additions
and
20 deletions
+84
-20
settings.py
addysalto_reading/addysalto_reading/settings.py
+2
-1
urls.py
addysalto_reading/addysalto_reading/urls.py
+2
-2
admin.py
addysalto_reading/bookshelf/admin.py
+9
-3
models.py
addysalto_reading/bookshelf/models.py
+31
-10
urls.py
addysalto_reading/bookshelf/urls.py
+8
-2
views.py
addysalto_reading/bookshelf/views.py
+32
-2
No files found.
addysalto_reading/addysalto_reading/settings.py
View file @
0d147dce
...
@@ -60,7 +60,7 @@ ROOT_URLCONF = 'addysalto_reading.urls'
...
@@ -60,7 +60,7 @@ ROOT_URLCONF = 'addysalto_reading.urls'
TEMPLATES
=
[
TEMPLATES
=
[
{
{
'BACKEND'
:
'django.template.backends.django.DjangoTemplates'
,
'BACKEND'
:
'django.template.backends.django.DjangoTemplates'
,
'DIRS'
:
[],
'DIRS'
:
[
os
.
path
.
join
(
BASE_DIR
,
'templates'
)
],
'APP_DIRS'
:
True
,
'APP_DIRS'
:
True
,
'OPTIONS'
:
{
'OPTIONS'
:
{
'context_processors'
:
[
'context_processors'
:
[
...
@@ -122,6 +122,7 @@ USE_TZ = True
...
@@ -122,6 +122,7 @@ USE_TZ = True
# https://docs.djangoproject.com/en/4.1/howto/static-files/
# https://docs.djangoproject.com/en/4.1/howto/static-files/
STATIC_URL
=
'static/'
STATIC_URL
=
'static/'
STATICFILES_DIRS
=
[
os
.
path
.
join
(
BASE_DIR
,
'static'
)]
# Default primary key field type
# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
...
...
addysalto_reading/addysalto_reading/urls.py
View file @
0d147dce
...
@@ -17,6 +17,6 @@ from django.contrib import admin
...
@@ -17,6 +17,6 @@ from django.contrib import admin
from
django.urls
import
include
,
path
from
django.urls
import
include
,
path
urlpatterns
=
[
urlpatterns
=
[
path
(
'
bookshelf/
'
,
include
(
'bookshelf.urls'
,
namespace
=
"bookshelf"
)),
path
(
''
,
include
(
'bookshelf.urls'
,
namespace
=
"bookshelf"
)),
path
(
'admin/'
,
admin
.
site
.
urls
),
path
(
'admin/'
,
admin
.
site
.
urls
),
]
]
addysalto_reading/bookshelf/admin.py
View file @
0d147dce
...
@@ -4,10 +4,16 @@ from .models import Author, Books
...
@@ -4,10 +4,16 @@ from .models import Author, Books
class
AuthorAdmin
(
admin
.
ModelAdmin
):
class
AuthorAdmin
(
admin
.
ModelAdmin
):
model
=
Author
model
=
Author
search_fields
=
(
'first_name'
,
'last_name'
)
list_display
=
(
'first_name'
,
'last_name'
,
'age'
,
'nationality'
,
'bio'
)
class
BooksAdmin
(
admin
.
ModelAdmin
):
class
BooksAdmin
(
admin
.
ModelAdmin
):
model
=
Books
model
=
Books
search_fields
=
(
'title'
,
'author'
)
list_display
=
(
'title'
,
'author'
,
'publisher'
,
'year_published'
,
'ISBN'
,
'blurb'
)
admin
.
site
.
register
(
Author
,
AuthorAdmin
)
admin
.
site
.
register
(
Author
,
AuthorAdmin
)
...
...
addysalto_reading/bookshelf/models.py
View file @
0d147dce
from
django.db
import
models
from
django.db
import
models
from
django.core.validators
import
MinValueValidator
,
MaxValueValidator
from
django.urls
import
reverse
import
datetime
class
Author
(
models
.
Model
):
class
Author
(
models
.
Model
):
first_name
=
models
.
CharField
(
max_length
=
100
)
first_name
=
models
.
CharField
(
max_length
=
100
,
default
=
''
)
last_name
=
models
.
CharField
(
max_length
=
100
)
last_name
=
models
.
CharField
(
max_length
=
100
,
default
=
''
)
age
=
models
.
PositiveSmallIntegerField
()
age
=
models
.
PositiveSmallIntegerField
(
default
=
'0'
)
nationality
=
models
.
CharField
(
max_length
=
100
)
nationality
=
models
.
CharField
(
max_length
=
100
,
default
=
''
)
bio
=
models
.
TextField
(
max_length
=
700
)
bio
=
models
.
TextField
(
max_length
=
700
,
default
=
''
)
def
__str__
(
self
):
return
'{} {}'
.
format
(
self
.
first_name
,
self
.
last_name
)
def
get_absolute_url
(
self
):
return
reverse
(
'bookshelf:authors-detail'
,
kwargs
=
{
'pk'
:
self
.
pk
})
class
Books
(
models
.
Model
):
class
Books
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
255
)
title
=
models
.
CharField
(
max_length
=
255
,
default
=
''
)
author
=
models
.
ForeignKey
(
Author
,
on_delete
=
models
.
CASCADE
)
author
=
models
.
ForeignKey
(
Author
,
on_delete
=
models
.
CASCADE
)
publisher
=
models
.
CharField
(
max_length
=
100
)
publisher
=
models
.
CharField
(
max_length
=
100
,
default
=
''
)
year_published
=
YEAR_PUBLISHED_CHOICES
=
[(
r
,
r
)
for
r
in
range
(
1454
,
datetime
.
date
.
today
()
.
year
+
1
)]
ISBN
=
models
.
IntegerField
(
max_length
=
13
)
year_published
=
models
.
PositiveIntegerField
(
choices
=
YEAR_PUBLISHED_CHOICES
,
blurb
=
models
.
TextField
()
default
=
datetime
.
datetime
.
today
()
.
year
)
\ No newline at end of file
ISBN
=
models
.
PositiveIntegerField
(
validators
=
[
MaxValueValidator
(
9999999999999
),
MinValueValidator
(
0000000000000
)],
default
=
1000000000000
)
blurb
=
models
.
TextField
(
default
=
''
)
def
__str__
(
self
):
return
'{} by {}, {}'
.
format
(
self
.
title
,
self
.
author
,
self
.
year_published
)
def
get_absolute_url
(
self
):
return
reverse
(
'bookshelf:books-detail'
,
kwargs
=
{
'pk'
:
self
.
pk
})
\ No newline at end of file
addysalto_reading/bookshelf/urls.py
View file @
0d147dce
from
django.urls
import
path
from
django.urls
import
path
from
.views
import
index
from
.views
import
index
,
homepage
,
BookListView
,
BookDetailView
,
AuthorListView
,
AuthorDetailView
urlpatterns
=
[
urlpatterns
=
[
path
(
''
,
index
,
name
=
'index'
),
path
(
''
,
index
,
name
=
'index'
),
path
(
'home'
,
homepage
,
name
=
'home'
),
path
(
'books'
,
BookListView
.
as_view
(),
name
=
'books-list'
),
path
(
'books/<int:pk>/details'
,
BookDetailView
.
as_view
(),
name
=
'books-detail'
),
path
(
'authors'
,
AuthorListView
.
as_view
(),
name
=
'authors-list'
),
path
(
'authors/<int:pk>/details'
,
AuthorDetailView
.
as_view
(),
name
=
'authors-detail'
),
]
]
app_name
=
"bookshelf"
app_name
=
"bookshelf"
addysalto_reading/bookshelf/views.py
View file @
0d147dce
from
django.shortcuts
import
render
from
django.shortcuts
import
render
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
django.views
import
View
from
django.views.generic.list
import
ListView
from
django.views.generic.detail
import
DetailView
from
.models
import
Books
,
Author
def
index
(
request
):
def
index
(
request
):
return
HttpResponse
(
'Hello World! This came from the index view'
)
return
HttpResponse
(
''
)
\ No newline at end of file
def
homepage
(
request
):
return
render
(
request
,
'bookshelf/home.html'
)
class
BookListView
(
ListView
):
model
=
Books
template_name
=
'bookshelf/books.html'
class
BookDetailView
(
DetailView
):
model
=
Books
template_name
=
'bookshelf/book_details.html'
class
AuthorListView
(
ListView
):
model
=
Author
template_name
=
'bookshelf/authors.html'
class
AuthorDetailView
(
DetailView
):
model
=
Author
template_name
=
'bookshelf/author_details.html'
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
()
.
get_context_data
(
**
kwargs
)
context
[
'books'
]
=
Books
.
objects
.
all
()
return
context
\ 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