diff --git a/apps/library/doc.py b/apps/library/doc.py index 5013d39..0014b77 100644 --- a/apps/library/doc.py +++ b/apps/library/doc.py @@ -186,7 +186,7 @@ book_detail_swagger = swagger_auto_schema( - Categories and collections the book belongs to - Number of pages - The book is specified by its ID in the URL path. + The book is specified by its slug in the URL path. """, operation_summary="Get Book Detail", tags=["Dobodbi - Library"], diff --git a/apps/library/models.py b/apps/library/models.py index 7128d8b..0fa5326 100644 --- a/apps/library/models.py +++ b/apps/library/models.py @@ -6,6 +6,7 @@ from django.conf import settings from filer.fields.image import FilerImageField from dj_language.field import LanguageField from utils import generate_slug_for_model +from utils.slug import generate_smart_slug from apps.account.models import User @@ -37,8 +38,8 @@ class BookCollection(models.Model): verbose_name_plural = _('Book Collections') def save(self, *args, **kwargs): - if not self.slug: - self.slug = generate_slug_for_model(BookCollection, self.title) + if not self.slug or not self.slug.strip(): + self.slug = generate_smart_slug(self.title, BookCollection, instance=self) super().save(*args, **kwargs) @@ -78,8 +79,8 @@ class Category(models.Model): return self.title def save(self, *args, **kwargs): - if not self.slug: - self.slug = generate_slug_for_model(Category, self.title) + if not self.slug or not self.slug.strip(): + self.slug = generate_smart_slug(self.title, Category, instance=self) super().save(*args, **kwargs) @property @@ -147,8 +148,8 @@ class Book(models.Model): return None def save(self, *args, **kwargs): - if not self.slug: - self.slug = generate_slug_for_model(Book, self.title) + if not self.slug or not self.slug.strip(): + self.slug = generate_smart_slug(self.title, Book, instance=self) super().save(*args, **kwargs) diff --git a/apps/library/urls.py b/apps/library/urls.py index b5099fc..8206da7 100644 --- a/apps/library/urls.py +++ b/apps/library/urls.py @@ -15,7 +15,7 @@ urlpatterns = [ path('pinned-collections/', PinnedBookCollectionListView.as_view(), name='pinned-collection-list'), path('collections/', MiddleBookCollectionListView.as_view(), name='collection-list'), path('books/', BookListView.as_view(), name='book-list'), - path('books//', BookDetailView.as_view(), name='book-detail'), + path('books//', BookDetailView.as_view(), name='book-detail'), path('books/downloaded/', DownloadedBooksListView.as_view(), name='downloaded-books-list'), path('books/download/', BookDownloadCreateAPIView.as_view(), name='book-download'), ] \ No newline at end of file diff --git a/apps/library/views.py b/apps/library/views.py index 90ef46d..78878f7 100644 --- a/apps/library/views.py +++ b/apps/library/views.py @@ -189,6 +189,7 @@ class BookDetailView(RetrieveAPIView): permission_classes = (IsAuthenticated,) authentication_classes = [TokenAuthentication] queryset = Book.objects.filter(status=True) + lookup_field = 'slug' @book_detail_swagger def get(self, request, *args, **kwargs):