Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
justinreyes_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
Justin Reyes
justinreyes_reading
Commits
08ab2928
Commit
08ab2928
authored
Mar 27, 2023
by
justin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrated and populated all models, fixed ISBN validator for Books
parent
d0c4552a
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
109 additions
and
41 deletions
+109
-41
admin.py
justinreyes_reading/bookshelf/admin.py
+8
-3
0001_initial.py
justinreyes_reading/bookshelf/migrations/0001_initial.py
+38
-0
0002_alter_books_isbn.py
...yes_reading/bookshelf/migrations/0002_alter_books_isbn.py
+19
-0
models.py
justinreyes_reading/bookshelf/models.py
+7
-2
db.sqlite3
justinreyes_reading/db.sqlite3
+0
-0
settings.py
justinreyes_reading/justinreyes_reading/settings.py
+37
-36
No files found.
justinreyes_reading/bookshelf/admin.py
View file @
08ab2928
from
django.contrib
import
admin
from
django.contrib
import
admin
from
models
import
Author
,
Books
from
.
models
import
Author
,
Books
class
AuthorAdmin
(
admin
.
ModelAdmin
):
class
AuthorAdmin
(
admin
.
ModelAdmin
):
model
=
Author
model
=
Author
list_display
=
(
list_display
=
(
"first_name"
,
"last_name"
,
"last_name"
,
"first_name"
,
"age"
,
"age"
,
"nationality"
,
"nationality"
,
"bio"
,
"
shortened_
bio"
,
)
)
search_fields
=
(
search_fields
=
(
"first_name"
,
"first_name"
,
...
@@ -17,6 +17,11 @@ class AuthorAdmin(admin.ModelAdmin):
...
@@ -17,6 +17,11 @@ class AuthorAdmin(admin.ModelAdmin):
)
)
list_filter
=
(
"nationality"
,)
list_filter
=
(
"nationality"
,)
def
shortened_bio
(
self
,
obj
):
return
obj
.
bio
[:
50
]
+
"..."
shortened_bio
.
short_description
=
"Biography"
class
BooksAdmin
(
admin
.
ModelAdmin
):
class
BooksAdmin
(
admin
.
ModelAdmin
):
model
=
Books
model
=
Books
...
...
justinreyes_reading/bookshelf/migrations/0001_initial.py
0 → 100644
View file @
08ab2928
# Generated by Django 4.1.7 on 2023-03-27 06:15
import
django.core.validators
from
django.db
import
migrations
,
models
import
django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
initial
=
True
dependencies
=
[
]
operations
=
[
migrations
.
CreateModel
(
name
=
'Author'
,
fields
=
[
(
'id'
,
models
.
BigAutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'first_name'
,
models
.
CharField
(
max_length
=
255
)),
(
'last_name'
,
models
.
CharField
(
max_length
=
255
)),
(
'age'
,
models
.
PositiveIntegerField
()),
(
'nationality'
,
models
.
CharField
(
max_length
=
255
)),
(
'bio'
,
models
.
TextField
(
max_length
=
700
)),
],
),
migrations
.
CreateModel
(
name
=
'Books'
,
fields
=
[
(
'id'
,
models
.
BigAutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'title'
,
models
.
CharField
(
max_length
=
255
)),
(
'publisher'
,
models
.
CharField
(
default
=
'Unknown'
,
max_length
=
255
)),
(
'year_published'
,
models
.
IntegerField
(
default
=
0
)),
(
'isbn'
,
models
.
PositiveBigIntegerField
(
validators
=
[
django
.
core
.
validators
.
MaxLengthValidator
(
13
)])),
(
'author'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'bookshelf.author'
)),
],
),
]
justinreyes_reading/bookshelf/migrations/0002_alter_books_isbn.py
0 → 100644
View file @
08ab2928
# Generated by Django 4.1.7 on 2023-03-27 06:55
import
bookshelf.models
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'bookshelf'
,
'0001_initial'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'books'
,
name
=
'isbn'
,
field
=
models
.
PositiveBigIntegerField
(
validators
=
[
bookshelf
.
models
.
validate_isbn
]),
),
]
justinreyes_reading/bookshelf/models.py
View file @
08ab2928
from
django.db
import
models
from
django.db
import
models
from
django.core.validators
import
MaxLengthValidator
from
django.core.exceptions
import
ValidationError
def
validate_isbn
(
value
):
if
len
(
str
(
value
))
!=
13
:
raise
ValidationError
(
"ISBN must be exactly 13 digits long."
)
class
Author
(
models
.
Model
):
class
Author
(
models
.
Model
):
...
@@ -21,7 +26,7 @@ class Books(models.Model):
...
@@ -21,7 +26,7 @@ class Books(models.Model):
default
=
"Unknown"
,
default
=
"Unknown"
,
)
)
year_published
=
models
.
IntegerField
(
default
=
0
)
year_published
=
models
.
IntegerField
(
default
=
0
)
isbn
=
models
.
PositiveBigIntegerField
(
validators
=
[
MaxLengthValidator
(
13
)
])
isbn
=
models
.
PositiveBigIntegerField
(
validators
=
[
validate_isbn
])
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
title
return
self
.
title
justinreyes_reading/db.sqlite3
0 → 100644
View file @
08ab2928
File added
justinreyes_reading/justinreyes_reading/settings.py
View file @
08ab2928
...
@@ -20,7 +20,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
...
@@ -20,7 +20,7 @@ BASE_DIR = Path(__file__).resolve().parent.parent
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY
=
'django-insecure-#$_y3fdp-jxw7@e54b&d)b1966h7g!@$#8#mk$@lqnq0_or((v'
SECRET_KEY
=
"django-insecure-#$_y3fdp-jxw7@e54b&d)b1966h7g!@$#8#mk$@lqnq0_or((v"
# SECURITY WARNING: don't run with debug turned on in production!
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG
=
True
DEBUG
=
True
...
@@ -31,52 +31,53 @@ ALLOWED_HOSTS = []
...
@@ -31,52 +31,53 @@ ALLOWED_HOSTS = []
# Application definition
# Application definition
INSTALLED_APPS
=
[
INSTALLED_APPS
=
[
'django.contrib.admin'
,
"django.contrib.admin"
,
'django.contrib.auth'
,
"django.contrib.auth"
,
'django.contrib.contenttypes'
,
"django.contrib.contenttypes"
,
'django.contrib.sessions'
,
"django.contrib.sessions"
,
'django.contrib.messages'
,
"django.contrib.messages"
,
'django.contrib.staticfiles'
,
"django.contrib.staticfiles"
,
"bookshelf"
,
]
]
MIDDLEWARE
=
[
MIDDLEWARE
=
[
'django.middleware.security.SecurityMiddleware'
,
"django.middleware.security.SecurityMiddleware"
,
'django.contrib.sessions.middleware.SessionMiddleware'
,
"django.contrib.sessions.middleware.SessionMiddleware"
,
'django.middleware.common.CommonMiddleware'
,
"django.middleware.common.CommonMiddleware"
,
'django.middleware.csrf.CsrfViewMiddleware'
,
"django.middleware.csrf.CsrfViewMiddleware"
,
'django.contrib.auth.middleware.AuthenticationMiddleware'
,
"django.contrib.auth.middleware.AuthenticationMiddleware"
,
'django.contrib.messages.middleware.MessageMiddleware'
,
"django.contrib.messages.middleware.MessageMiddleware"
,
'django.middleware.clickjacking.XFrameOptionsMiddleware'
,
"django.middleware.clickjacking.XFrameOptionsMiddleware"
,
]
]
ROOT_URLCONF
=
'justinreyes_reading.urls'
ROOT_URLCONF
=
"justinreyes_reading.urls"
TEMPLATES
=
[
TEMPLATES
=
[
{
{
'BACKEND'
:
'django.template.backends.django.DjangoTemplates'
,
"BACKEND"
:
"django.template.backends.django.DjangoTemplates"
,
'DIRS'
:
[],
"DIRS"
:
[],
'APP_DIRS'
:
True
,
"APP_DIRS"
:
True
,
'OPTIONS'
:
{
"OPTIONS"
:
{
'context_processors'
:
[
"context_processors"
:
[
'django.template.context_processors.debug'
,
"django.template.context_processors.debug"
,
'django.template.context_processors.request'
,
"django.template.context_processors.request"
,
'django.contrib.auth.context_processors.auth'
,
"django.contrib.auth.context_processors.auth"
,
'django.contrib.messages.context_processors.messages'
,
"django.contrib.messages.context_processors.messages"
,
],
],
},
},
},
},
]
]
WSGI_APPLICATION
=
'justinreyes_reading.wsgi.application'
WSGI_APPLICATION
=
"justinreyes_reading.wsgi.application"
# Database
# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
DATABASES
=
{
DATABASES
=
{
'default'
:
{
"default"
:
{
'ENGINE'
:
'django.db.backends.sqlite3'
,
"ENGINE"
:
"django.db.backends.sqlite3"
,
'NAME'
:
BASE_DIR
/
'db.sqlite3'
,
"NAME"
:
BASE_DIR
/
"db.sqlite3"
,
}
}
}
}
...
@@ -86,16 +87,16 @@ DATABASES = {
...
@@ -86,16 +87,16 @@ DATABASES = {
AUTH_PASSWORD_VALIDATORS
=
[
AUTH_PASSWORD_VALIDATORS
=
[
{
{
'NAME'
:
'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'
,
"NAME"
:
"django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
,
},
},
{
{
'NAME'
:
'django.contrib.auth.password_validation.MinimumLengthValidator'
,
"NAME"
:
"django.contrib.auth.password_validation.MinimumLengthValidator"
,
},
},
{
{
'NAME'
:
'django.contrib.auth.password_validation.CommonPasswordValidator'
,
"NAME"
:
"django.contrib.auth.password_validation.CommonPasswordValidator"
,
},
},
{
{
'NAME'
:
'django.contrib.auth.password_validation.NumericPasswordValidator'
,
"NAME"
:
"django.contrib.auth.password_validation.NumericPasswordValidator"
,
},
},
]
]
...
@@ -103,9 +104,9 @@ AUTH_PASSWORD_VALIDATORS = [
...
@@ -103,9 +104,9 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization
# Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/
# https://docs.djangoproject.com/en/4.1/topics/i18n/
LANGUAGE_CODE
=
'en-us'
LANGUAGE_CODE
=
"en-us"
TIME_ZONE
=
'UTC'
TIME_ZONE
=
"Asia/Manila"
USE_I18N
=
True
USE_I18N
=
True
...
@@ -115,9 +116,9 @@ USE_TZ = True
...
@@ -115,9 +116,9 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# Static files (CSS, JavaScript, Images)
# 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/"
# 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
DEFAULT_AUTO_FIELD
=
'django.db.models.BigAutoField'
DEFAULT_AUTO_FIELD
=
"django.db.models.BigAutoField"
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