Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
bellapanghulan_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
Ysabella Panghulan
bellapanghulan_reading
Commits
d66fda38
Commit
d66fda38
authored
Mar 27, 2023
by
Ysabella Panghulan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
edited Books class in models.py and admin.py
parent
77168d34
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
40 additions
and
5 deletions
+40
-5
admin.cpython-310.pyc
...hulan_reading/bookshelf/__pycache__/admin.cpython-310.pyc
+0
-0
models.cpython-310.pyc
...ulan_reading/bookshelf/__pycache__/models.cpython-310.pyc
+0
-0
admin.py
bellapanghulan_reading/bookshelf/admin.py
+2
-2
0002_alter_books_blurb_alter_books_year_published.py
...ions/0002_alter_books_blurb_alter_books_year_published.py
+24
-0
0002_alter_books_blurb_alter_books_year_published.cpython-310.pyc
...er_books_blurb_alter_books_year_published.cpython-310.pyc
+0
-0
models.py
bellapanghulan_reading/bookshelf/models.py
+14
-3
No files found.
bellapanghulan_reading/bookshelf/__pycache__/admin.cpython-310.pyc
View file @
d66fda38
No preview for this file type
bellapanghulan_reading/bookshelf/__pycache__/models.cpython-310.pyc
View file @
d66fda38
No preview for this file type
bellapanghulan_reading/bookshelf/admin.py
View file @
d66fda38
...
...
@@ -3,13 +3,13 @@ from .models import Author, Books
# Register your models here.
class
AuthorAdmin
(
admin
.
ModelAdmin
):
model
=
Author
list_display
=
(
'first_name'
,
'last_name'
,
'age'
,
'nationality'
,
'bio'
)
list_display
=
(
'first_name'
,
'last_name'
,
'age'
,
'nationality'
,)
search_fields
=
[
'first_name'
,
'last_name'
,]
list_filter
=
(
'first_name'
,
'last_name'
,)
class
BooksAdmin
(
admin
.
ModelAdmin
):
model
=
Books
list_display
=
(
'title'
,
'author'
,
'publisher'
,
'year_published'
,
'ISBN'
,
'blurb'
)
list_display
=
(
'title'
,
'author'
,
'publisher'
,
'year_published'
,
'ISBN'
,)
search_fields
=
[
'title'
,
'author'
,
'publisher'
,
'ISBN'
]
list_filter
=
(
'author'
,
'publisher'
,
'year_published'
,)
...
...
bellapanghulan_reading/bookshelf/migrations/0002_alter_books_blurb_alter_books_year_published.py
0 → 100644
View file @
d66fda38
# Generated by Django 4.1.3 on 2023-03-27 07:23
import
bookshelf.models
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'bookshelf'
,
'0001_initial'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'books'
,
name
=
'blurb'
,
field
=
models
.
TextField
(
validators
=
[
bookshelf
.
models
.
Books
.
validate_wordCount
]),
),
migrations
.
AlterField
(
model_name
=
'books'
,
name
=
'year_published'
,
field
=
models
.
IntegerField
(
blank
=
True
,
null
=
True
,
validators
=
[
bookshelf
.
models
.
Books
.
validate_year
]),
),
]
bellapanghulan_reading/bookshelf/migrations/__pycache__/0002_alter_books_blurb_alter_books_year_published.cpython-310.pyc
0 → 100644
View file @
d66fda38
File added
bellapanghulan_reading/bookshelf/models.py
View file @
d66fda38
from
datetime
import
datetime
from
django.db
import
models
from
django.core.exceptions
import
ValidationError
from
django.core.validators
import
MinLengthValidator
# Create your models here.
class
Author
(
models
.
Model
):
...
...
@@ -17,16 +17,27 @@ class Books(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'
)
def
validate_year
(
value
):
if
value
>
int
(
datetime
.
now
()
.
strftime
(
"
%
Y"
))
or
value
<
1000
:
raise
ValidationError
(
'Please enter a valid year (e.g. 2023)'
)
def
validate_ISBN
(
value
):
if
len
(
value
)
!=
13
:
raise
ValidationError
(
'Must be exactly 13 digits.'
)
if
not
value
.
isdigit
():
raise
ValidationError
(
'Must only be digits.'
)
def
validate_wordCount
(
value
):
word_count
=
len
(
value
.
split
())
if
word_count
<
100
:
raise
ValidationError
(
'Word count is less than 100.'
)
if
word_count
>
200
:
raise
ValidationError
(
'Word count is greater than 200.'
)
year_published
=
models
.
IntegerField
(
validators
=
[
validate_year
],
blank
=
True
,
null
=
True
)
ISBN
=
models
.
CharField
(
max_length
=
13
,
validators
=
[
validate_ISBN
])
blurb
=
models
.
TextField
(
max_length
=
200
,
validators
=
[
MinLengthValidator
(
100
)
])
blurb
=
models
.
TextField
(
validators
=
[
validate_wordCount
])
def
__str__
(
self
):
...
...
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