diff --git a/bookshelf_management/apps/mgmt/__pycache__/admin.cpython-36.pyc b/bookshelf_management/apps/mgmt/__pycache__/admin.cpython-36.pyc index b84122f..05eee53 100644 Binary files a/bookshelf_management/apps/mgmt/__pycache__/admin.cpython-36.pyc and b/bookshelf_management/apps/mgmt/__pycache__/admin.cpython-36.pyc differ diff --git a/bookshelf_management/apps/mgmt/__pycache__/models.cpython-36.pyc b/bookshelf_management/apps/mgmt/__pycache__/models.cpython-36.pyc index a855f1b..c7ea28e 100644 Binary files a/bookshelf_management/apps/mgmt/__pycache__/models.cpython-36.pyc and b/bookshelf_management/apps/mgmt/__pycache__/models.cpython-36.pyc differ diff --git a/bookshelf_management/apps/mgmt/admin.py b/bookshelf_management/apps/mgmt/admin.py index 8197c69..685a19d 100644 --- a/bookshelf_management/apps/mgmt/admin.py +++ b/bookshelf_management/apps/mgmt/admin.py @@ -1,6 +1,7 @@ from django.contrib import admin -from .models import Bookshelf, Book +from .models import Bookshelf, Book, BookshelfToBook admin.site.register(Bookshelf) admin.site.register(Book) +admin.site.register(BookshelfToBook) diff --git a/bookshelf_management/apps/mgmt/models.py b/bookshelf_management/apps/mgmt/models.py index 7e7ef85..bd55992 100644 --- a/bookshelf_management/apps/mgmt/models.py +++ b/bookshelf_management/apps/mgmt/models.py @@ -23,16 +23,21 @@ class Author(models.Model): ''' class Bookshelf(models.Model): - id = models.IntegerField(db_column='pk', primary_key=True) + id = models.AutoField(db_column='pk', primary_key=True) bookshelf = models.CharField(max_length=255, null=False) downloads = models.IntegerField(default=0) release_date = models.DateField(null=True) class Meta: db_table = "bookshelves" + def __str__(self): + return str(self.bookshelf) + + + class Book(models.Model): - id = models.IntegerField(db_column='pk', primary_key=True) + id = models.AutoField(db_column='pk', primary_key=True) copyrighted = models.IntegerField(null=True, default=0) updatemode = models.IntegerField(null=True, default=0) release_date = models.DateField(null=True) @@ -41,6 +46,26 @@ class Book(models.Model): downloads = models.IntegerField(null=True, default=0) title = models.TextField(max_length=255, default="", null=True, blank=True) nonfiling = models.IntegerField(default=0) + class Meta: + db_table = "books" + def __str__(self): + return str(self.title) + def save(self, *args, **kwargs): + return + def delete(self, *args, **kwargs): + return + + + +class BookshelfToBook(models.Model): + fk_books = models.ForeignKey(Book, db_column='fk_books', to_field='id', on_delete=models.CASCADE,) + fk_bookshelves = models.ForeignKey(Bookshelf, db_column='fk_bookshelves', to_field='id', on_delete=models.CASCADE) + class Meta: + db_table = "mn_books_bookshelves" + unique_together = (("fk_books", "fk_bookshelves"),) + def __str__(self): + return str(self.fk_books.title) + ' in bookshelf ' + str(self.fk_bookshelves.bookshelf) + ''' # using a custom save method in order to update the "updated" timestamp when specific fields are updated @@ -114,6 +139,4 @@ class Book(models.Model): self._pandata=Pandata() self._pandata.load(self.yaml) return self._pandata.metadata -''' - class Meta: - db_table = "books" \ No newline at end of file +''' \ No newline at end of file