diff --git a/books/forms.py b/books/forms.py index b023028f..88c58c17 100644 --- a/books/forms.py +++ b/books/forms.py @@ -24,6 +24,8 @@ class BookForm(forms.ModelForm): fields = [ 'id', 'title', + 'source_site', + 'source_url', 'isbn', 'author', 'pub_house', diff --git a/books/models.py b/books/models.py index aa539fc8..9eecb479 100644 --- a/books/models.py +++ b/books/models.py @@ -3,7 +3,8 @@ import django.contrib.postgres.fields as postgres from django.utils.translation import ugettext_lazy as _ from django.db import models from django.core.serializers.json import DjangoJSONEncoder -from common.models import Resource, Mark, Review, Tag +from django.shortcuts import reverse +from common.models import Entity, Mark, Review, Tag from boofilsic.settings import BOOK_MEDIA_PATH_ROOT, DEFAULT_BOOK_IMAGE from django.utils import timezone @@ -19,7 +20,7 @@ def book_cover_path(instance, filename): return root + timezone.now().strftime('%Y/%m/%d') + f'{filename}' -class Book(Resource): +class Book(Entity): # widely recognized name, usually in Chinese title = models.CharField(_("title"), max_length=200) subtitle = models.CharField(_("subtitle"), blank=True, default='', max_length=200) @@ -46,7 +47,7 @@ class Book(Resource): # since data origin is not formatted and might be CNY USD or other currency, use char instead price = models.CharField(_("pricing"), blank=True, default='', max_length=50) pages = models.PositiveIntegerField(_("pages"), null=True, blank=True) - isbn = models.CharField(_("ISBN"), blank=True, null=True, max_length=20, unique=True, db_index=True) + isbn = models.CharField(_("ISBN"), blank=True, null=True, max_length=20, db_index=True) # to store previously scrapped data cover = models.ImageField(_("cover picture"), upload_to=book_cover_path, default=DEFAULT_BOOK_IMAGE, blank=True) contents = models.TextField(blank=True, default="") @@ -66,6 +67,9 @@ class Book(Resource): def __str__(self): return self.title + + def get_absolute_url(self): + return reverse("books:retrieve", args=[self.id]) def get_tags_manager(self): return self.book_tags @@ -76,8 +80,6 @@ class Book(Resource): class BookMark(Mark): - # maybe this is the better solution, for it has less complex index - # book = models.ForeignKey(Book, on_delete=models.CASCADE, related_name='book_marks', null=True, unique=True) book = models.ForeignKey(Book, on_delete=models.CASCADE, related_name='book_marks', null=True) class Meta: constraints = [ diff --git a/books/templates/books/create_update.html b/books/templates/books/create_update.html index 3f9406c3..a6c9427c 100644 --- a/books/templates/books/create_update.html +++ b/books/templates/books/create_update.html @@ -50,9 +50,30 @@ diff --git a/books/templates/books/scrape.html b/books/templates/books/scrape.html index cd00eb2b..8626855f 100644 --- a/books/templates/books/scrape.html +++ b/books/templates/books/scrape.html @@ -99,7 +99,7 @@ ISBN: 9787020104345 diff --git a/movies/templates/movies/scrape.html b/movies/templates/movies/scrape.html index 85212f15..c60a41aa 100644 --- a/movies/templates/movies/scrape.html +++ b/movies/templates/movies/scrape.html @@ -97,7 +97,7 @@