Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
rachpurisima_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
Rachel
rachpurisima_reading
Commits
25677754
Commit
25677754
authored
Mar 28, 2023
by
rachbit
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
created admin panel
parent
cf9ca778
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
3 deletions
+84
-3
admin.py
rachpurisima_reading/bookshelf/admin.py
+15
-1
0001_initial.py
rachpurisima_reading/bookshelf/migrations/0001_initial.py
+37
-0
0002_auto_20230328_1255.py
...a_reading/bookshelf/migrations/0002_auto_20230328_1255.py
+29
-0
models.py
rachpurisima_reading/bookshelf/models.py
+3
-2
No files found.
rachpurisima_reading/bookshelf/admin.py
View file @
25677754
from
django.contrib
import
admin
from
django.contrib
import
admin
from
.models
import
Author
,
Book
# Register your models here.
class
AuthorAdmin
(
admin
.
ModelAdmin
):
model
=
Author
list_display
=
(
"last_name"
,
"first_name"
,
"nationality"
,
"bio"
)
search_fields
=
(
"first_name"
,
"last_name"
)
class
BooksAdmin
(
admin
.
ModelAdmin
):
model
=
Book
list_display
=
(
"title"
,
"author"
,
"blurb"
,
"publisher"
,
"year_published"
,
"ISBN"
)
search_fields
=
(
"title"
,
"author"
,
"year_published"
,
"publisher"
,
"ISBN"
)
# registering the model and the admin is what tells
# Django that admin pages must be generated for the models specified
admin
.
site
.
register
(
Author
,
AuthorAdmin
)
admin
.
site
.
register
(
Book
,
BooksAdmin
)
rachpurisima_reading/bookshelf/migrations/0001_initial.py
0 → 100644
View file @
25677754
# Generated by Django 3.2 on 2023-03-28 12:41
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
=
100
)),
(
'last_name'
,
models
.
CharField
(
max_length
=
100
)),
(
'age'
,
models
.
IntegerField
()),
(
'nationality'
,
models
.
CharField
(
max_length
=
100
)),
(
'bio'
,
models
.
TextField
()),
],
),
migrations
.
CreateModel
(
name
=
'Books'
,
fields
=
[
(
'title'
,
models
.
CharField
(
max_length
=
100
)),
(
'publisher'
,
models
.
CharField
(
max_length
=
100
)),
(
'year_published'
,
models
.
CharField
(
max_length
=
4
,
validators
=
[
django
.
core
.
validators
.
RegexValidator
(
'^
\\
d{1,10}$'
)])),
(
'ISBN'
,
models
.
CharField
(
max_length
=
13
,
primary_key
=
True
,
serialize
=
False
,
validators
=
[
django
.
core
.
validators
.
MinLengthValidator
(
13
),
django
.
core
.
validators
.
RegexValidator
(
'^
\\
d{1,10}$'
)])),
(
'author'
,
models
.
ForeignKey
(
default
=
''
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'bookshelf.author'
)),
],
),
]
rachpurisima_reading/bookshelf/migrations/0002_auto_20230328_1255.py
0 → 100644
View file @
25677754
# Generated by Django 3.2 on 2023-03-28 12:55
import
django.core.validators
from
django.db
import
migrations
,
models
import
django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'bookshelf'
,
'0001_initial'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'Book'
,
fields
=
[
(
'title'
,
models
.
CharField
(
max_length
=
100
)),
(
'publisher'
,
models
.
CharField
(
max_length
=
100
)),
(
'year_published'
,
models
.
CharField
(
max_length
=
4
,
validators
=
[
django
.
core
.
validators
.
RegexValidator
(
'^
\\
d{1,10}$'
)])),
(
'ISBN'
,
models
.
CharField
(
max_length
=
13
,
primary_key
=
True
,
serialize
=
False
,
validators
=
[
django
.
core
.
validators
.
MinLengthValidator
(
13
),
django
.
core
.
validators
.
RegexValidator
(
'^
\\
d{1,10}$'
)])),
(
'blurb'
,
models
.
CharField
(
max_length
=
200
)),
(
'author'
,
models
.
ForeignKey
(
default
=
''
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'bookshelf.author'
)),
],
),
migrations
.
DeleteModel
(
name
=
'Books'
,
),
]
rachpurisima_reading/bookshelf/models.py
View file @
25677754
...
@@ -12,13 +12,14 @@ class Author(models.Model):
...
@@ -12,13 +12,14 @@ class Author(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
'{} {}'
.
format
(
self
.
first_name
,
self
.
last_name
)
return
'{} {}'
.
format
(
self
.
first_name
,
self
.
last_name
)
class
Book
s
(
models
.
Model
):
class
Book
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
100
)
title
=
models
.
CharField
(
max_length
=
100
)
author
=
models
.
ForeignKey
(
Author
,
on_delete
=
models
.
CASCADE
,
default
=
""
)
author
=
models
.
ForeignKey
(
Author
,
on_delete
=
models
.
CASCADE
,
default
=
""
)
publisher
=
models
.
CharField
(
max_length
=
100
)
publisher
=
models
.
CharField
(
max_length
=
100
)
year_published
=
models
.
IntegerField
(
validators
=
[
MinValueValidator
(
0
),
MaxValueValidator
(
2023
)])
year_published
=
models
.
CharField
(
max_length
=
4
,
validators
=
[
RegexValidator
(
r'^\d{1,10}$'
)])
ISBN
=
models
.
CharField
(
primary_key
=
True
,
max_length
=
13
,
validators
=
[
MinLengthValidator
(
13
),
RegexValidator
(
r'^\d{1,10}$'
)])
ISBN
=
models
.
CharField
(
primary_key
=
True
,
max_length
=
13
,
validators
=
[
MinLengthValidator
(
13
),
RegexValidator
(
r'^\d{1,10}$'
)])
blurb
=
models
.
CharField
(
max_length
=
200
)
def
__str__
(
self
):
def
__str__
(
self
):
return
'{}'
.
format
(
self
.
title
)
return
'{}'
.
format
(
self
.
title
)
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