Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
javing_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
John Aidan Vincent M. Ng
javing_reading
Commits
890a7d8a
Commit
890a7d8a
authored
Mar 27, 2023
by
Javi Ng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wrote code for models and admin pages
parent
ce941a5a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
1 deletion
+50
-1
.DS_Store
.DS_Store
+0
-0
admin.py
javing_reading/bookshelf/admin.py
+29
-1
models.py
javing_reading/bookshelf/models.py
+21
-0
No files found.
.DS_Store
View file @
890a7d8a
No preview for this file type
javing_reading/bookshelf/admin.py
View file @
890a7d8a
from
django.contrib
import
admin
from
django.contrib
import
admin
from
.models
import
Author
,
Book
# Register your models here.
# Register your models here.
# show books in page for authors
class
BookInline
(
admin
.
TabularInline
):
model
=
Book
class
AuthorAdmin
(
admin
.
ModelAdmin
):
model
=
Author
list_display
=
(
"first_name"
,
"last_name"
,
"age"
,
"nationality"
)
search_fields
=
(
"first_name"
,
"last_name"
)
list_filter
=
(
"nationality"
)
inlines
=
[
BookInline
]
class
BookAdmin
(
admin
.
ModelAdmin
):
list_display
=
(
"title"
,
"get_author"
,
"year_published"
,
"ISBN"
)
list_filter
=
(
"get_author"
,
"publisher"
)
def
get_author
(
self
,
obj
):
return
obj
.
author
.
title
# title of column for get_author
get_author
.
short_description
=
"Author"
# sorting by Author
get_author
.
admin_order_field
=
"Author"
admin
.
site
.
register
(
Author
,
AuthorAdmin
)
admin
.
site
.
register
(
Book
,
BookAdmin
)
\ No newline at end of file
javing_reading/bookshelf/models.py
View file @
890a7d8a
from
django.db
import
models
from
django.db
import
models
# Create your models here.
# Create your models here.
class
Author
(
models
.
Model
):
first_name
=
models
.
CharField
(
max_length
=
50
)
last_name
=
models
.
CharField
(
max_length
=
30
)
age
=
models
.
IntegerField
(
default
=
10
)
nationality
=
models
.
CharField
(
max_length
=
50
)
bio
=
models
.
TextField
(
max_length
=
700
)
class
Book
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
50
)
author
=
models
.
ForeignKey
(
Author
,
on_delete
=
models
.
CASCADE
)
publisher
=
models
.
CharField
(
max_length
=
100
)
year_published
=
models
.
IntegerField
(
default
=
1984
)
ISBN
=
models
.
IntegerField
(
max_value
=
9999999999999
,
min_value
=
1000000000000
)
blurb
=
models
.
TextField
(
min_length
=
100
,
max_length
=
200
)
\ 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