Skip to content

Commit

Permalink
Merge pull request #15 from rkshaon/rkshaon
Browse files Browse the repository at this point in the history
backend
  • Loading branch information
rkshaon authored Sep 6, 2024
2 parents d4ad482 + 039f02a commit bdcdf1b
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 1 deletion.
24 changes: 23 additions & 1 deletion backend/book_api/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
from django.contrib import admin

from book_api.models import Genre
from book_api.models import Topic
from book_api.models import Book


@admin.register(Genre)
class GenreAdmin(admin.ModelAdmin):
list_display = [
'id', 'name',
]
list_display_links = ['name']
search_fields = ['name']
readonly_fields = ['id']


@admin.register(Topic)
class TopicAdmin(admin.ModelAdmin):
list_display = [
'id', 'name',
]
list_display_links = ['name']
search_fields = ['name']
readonly_fields = ['id']


@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
list_display = [
Expand All @@ -14,7 +36,7 @@ class BookAdmin(admin.ModelAdmin):
'title',
]
list_filter = [
'authors', 'publisher',
'genres', 'topics', 'authors', 'publisher',
]
search_fields = [
'title', 'edition', 'isbn',
Expand Down
25 changes: 25 additions & 0 deletions backend/book_api/migrations/0005_genre_book_genres.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 5.1.1 on 2024-09-06 21:17

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('book_api', '0004_alter_book_book'),
]

operations = [
migrations.CreateModel(
name='Genre',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255, unique=True)),
],
),
migrations.AddField(
model_name='book',
name='genres',
field=models.ManyToManyField(related_name='books', to='book_api.genre'),
),
]
20 changes: 20 additions & 0 deletions backend/book_api/migrations/0006_topic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 5.1.1 on 2024-09-06 21:21

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('book_api', '0005_genre_book_genres'),
]

operations = [
migrations.CreateModel(
name='Topic',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255, unique=True)),
],
),
]
18 changes: 18 additions & 0 deletions backend/book_api/migrations/0007_book_topics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1.1 on 2024-09-06 21:23

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('book_api', '0006_topic'),
]

operations = [
migrations.AddField(
model_name='book',
name='topics',
field=models.ManyToManyField(related_name='books', to='book_api.topic'),
),
]
22 changes: 22 additions & 0 deletions backend/book_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,30 @@ def book_upload_path(instance, filename):
return os.path.join('books', new_filename)


class Genre(models.Model):
name = models.CharField(max_length=255, unique=True)

def __str__(self) -> str:
return self.name


class Topic(models.Model):
name = models.CharField(max_length=255, unique=True)

def __str__(self) -> str:
return self.name


class Book(models.Model):
title = models.CharField(max_length=255)
genres = models.ManyToManyField(
'book_api.Genre',
related_name='books'
)
topics = models.ManyToManyField(
'book_api.Topic',
related_name='books'
)
authors = models.ManyToManyField(
'author_api.Author',
related_name='books')
Expand Down
Binary file modified backend/db.sqlite3
Binary file not shown.

0 comments on commit bdcdf1b

Please sign in to comment.