Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gabgeraldo_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
Gabriel Geraldo
gabgeraldo_reading
Commits
704c2091
Commit
704c2091
authored
Mar 28, 2023
by
Gabriel Geraldo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implemented bookshelf app with Author, Books models
parent
bb858752
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
115 additions
and
1 deletion
+115
-1
__init__.py
gabgeraldo_reading/bookshelf/__init__.py
+0
-0
admin.py
gabgeraldo_reading/bookshelf/admin.py
+17
-0
apps.py
gabgeraldo_reading/bookshelf/apps.py
+6
-0
0001_initial.py
gabgeraldo_reading/bookshelf/migrations/0001_initial.py
+39
-0
__init__.py
gabgeraldo_reading/bookshelf/migrations/__init__.py
+0
-0
models.py
gabgeraldo_reading/bookshelf/models.py
+32
-0
tests.py
gabgeraldo_reading/bookshelf/tests.py
+3
-0
urls.py
gabgeraldo_reading/bookshelf/urls.py
+9
-0
views.py
gabgeraldo_reading/bookshelf/views.py
+6
-0
settings.py
gabgeraldo_reading/gabgeraldo_reading/settings.py
+1
-0
urls.py
gabgeraldo_reading/gabgeraldo_reading/urls.py
+2
-1
No files found.
gabgeraldo_reading/bookshelf/__init__.py
0 → 100644
View file @
704c2091
gabgeraldo_reading/bookshelf/admin.py
0 → 100644
View file @
704c2091
from
django.contrib
import
admin
from
.models
import
Author
,
Books
class
AuthorAdmin
(
admin
.
ModelAdmin
):
model
=
Author
list_display
=
(
'first_name'
,
'last_name'
,
'bio'
)
search_fields
=
(
'first_name'
,
'last_name'
)
list_filter
=
(
'nationality'
,
'age'
)
class
BooksAdmin
(
admin
.
ModelAdmin
):
model
=
Books
list_display
=
(
'isbn'
,
'title'
,
'author'
,
'blurb'
)
search_fields
=
(
'title'
,
'isbn'
)
list_filter
=
(
'author'
,
'publisher'
,
'year_published'
)
admin
.
site
.
register
(
Author
,
AuthorAdmin
)
admin
.
site
.
register
(
Books
,
BooksAdmin
)
gabgeraldo_reading/bookshelf/apps.py
0 → 100644
View file @
704c2091
from
django.apps
import
AppConfig
class
BookshelfConfig
(
AppConfig
):
default_auto_field
=
'django.db.models.BigAutoField'
name
=
'bookshelf'
gabgeraldo_reading/bookshelf/migrations/0001_initial.py
0 → 100644
View file @
704c2091
# Generated by Django 4.1.7 on 2023-03-28 13:20
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
(
max_length
=
255
)),
(
'year_published'
,
models
.
PositiveIntegerField
(
validators
=
[
django
.
core
.
validators
.
MaxValueValidator
(
2023
)])),
(
'isbn'
,
models
.
PositiveIntegerField
(
unique
=
True
,
validators
=
[
django
.
core
.
validators
.
MaxValueValidator
(
9999999999999
),
django
.
core
.
validators
.
MinValueValidator
(
1000000000000
)])),
(
'blurb'
,
models
.
TextField
(
validators
=
[
django
.
core
.
validators
.
MaxLengthValidator
(
200
),
django
.
core
.
validators
.
MinLengthValidator
(
100
)])),
(
'author'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'bookshelf.author'
)),
],
),
]
gabgeraldo_reading/bookshelf/migrations/__init__.py
0 → 100644
View file @
704c2091
gabgeraldo_reading/bookshelf/models.py
0 → 100644
View file @
704c2091
from
django.db
import
models
from
django.core.validators
import
MinValueValidator
,
MaxValueValidator
,
MinLengthValidator
,
MaxLengthValidator
from
django.utils.timezone
import
datetime
# Create your models here.
class
Author
(
models
.
Model
):
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
)
def
__str__
(
self
):
return
f
"{self.first_name} {self.last_name}"
class
Books
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
255
)
author
=
models
.
ForeignKey
(
Author
,
on_delete
=
models
.
CASCADE
)
publisher
=
models
.
CharField
(
max_length
=
255
)
year_published
=
models
.
PositiveIntegerField
(
validators
=
[
MaxValueValidator
(
datetime
.
today
()
.
year
)]
)
isbn
=
models
.
PositiveIntegerField
(
validators
=
[
MaxValueValidator
(
9999999999999
),
MinValueValidator
(
1000000000000
)],
unique
=
True
)
blurb
=
models
.
TextField
(
validators
=
[
MaxLengthValidator
(
200
),
MinLengthValidator
(
100
)]
)
def
__str__
(
self
):
return
f
"{self.title} by {self.author}"
\ No newline at end of file
gabgeraldo_reading/bookshelf/tests.py
0 → 100644
View file @
704c2091
from
django.test
import
TestCase
# Create your tests here.
gabgeraldo_reading/bookshelf/urls.py
0 → 100644
View file @
704c2091
from
django.urls
import
path
from
.views
import
index
urlpatterns
=
[
path
(
''
,
index
,
name
=
'index'
)
]
app_name
=
"bookshelf"
\ No newline at end of file
gabgeraldo_reading/bookshelf/views.py
0 → 100644
View file @
704c2091
from
django.shortcuts
import
render
from
django.http
import
HttpResponse
# Create your views here.
def
index
(
request
):
return
HttpResponse
(
'initialized bookshelf views'
)
\ No newline at end of file
gabgeraldo_reading/gabgeraldo_reading/settings.py
View file @
704c2091
...
...
@@ -41,6 +41,7 @@ INSTALLED_APPS = [
'django.contrib.sessions'
,
'django.contrib.messages'
,
'django.contrib.staticfiles'
,
'bookshelf'
,
]
MIDDLEWARE
=
[
...
...
gabgeraldo_reading/gabgeraldo_reading/urls.py
View file @
704c2091
...
...
@@ -14,8 +14,9 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from
django.contrib
import
admin
from
django.urls
import
path
from
django.urls
import
include
,
path
urlpatterns
=
[
path
(
'admin/'
,
admin
.
site
.
urls
),
path
(
'bookshelf/'
,
include
(
'bookshelf.urls'
,
namespace
=
"bookshelf"
))
]
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