diff --git a/ram/bookshelf/admin.py b/ram/bookshelf/admin.py index 34027e0..1393380 100644 --- a/ram/bookshelf/admin.py +++ b/ram/bookshelf/admin.py @@ -26,7 +26,7 @@ class BookAdmin(SortableAdminBase, admin.ModelAdmin): "get_authors", "get_publisher", "publication_year", - "numbers_of_pages" + "number_of_pages" ) search_fields = ("title", "publisher__name", "authors__last_name") list_filter = ("publisher__name", "authors") diff --git a/ram/bookshelf/migrations/0004_rename_numbers_of_pages_book_number_of_pages.py b/ram/bookshelf/migrations/0004_rename_numbers_of_pages_book_number_of_pages.py new file mode 100644 index 0000000..fed0bab --- /dev/null +++ b/ram/bookshelf/migrations/0004_rename_numbers_of_pages_book_number_of_pages.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.5 on 2023-10-02 20:38 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookshelf", "0003_bookimage"), + ] + + operations = [ + migrations.RenameField( + model_name="book", + old_name="numbers_of_pages", + new_name="number_of_pages", + ), + ] diff --git a/ram/bookshelf/models.py b/ram/bookshelf/models.py index c170be8..107dcd7 100644 --- a/ram/bookshelf/models.py +++ b/ram/bookshelf/models.py @@ -1,6 +1,7 @@ from uuid import uuid4 from django.db import models from django.conf import settings +from django.urls import reverse from django_countries.fields import CountryField from ckeditor_uploader.fields import RichTextUploadingField @@ -41,7 +42,7 @@ class Book(models.Model): choices=settings.LANGUAGES, default='en' ) - numbers_of_pages = models.SmallIntegerField(null=True, blank=True) + number_of_pages = models.SmallIntegerField(null=True, blank=True) publication_year = models.SmallIntegerField(null=True, blank=True) purchase_date = models.DateField(null=True, blank=True) tags = models.ManyToManyField( @@ -58,7 +59,7 @@ class Book(models.Model): return self.publisher.name # def get_absolute_url(self): - # return reverse("rolling_stock", kwargs={"uuid": self.uuid}) + # return reverse("books", kwargs={"uuid": self.uuid}) class BookImage(Image): diff --git a/ram/portal/templates/books.html b/ram/portal/templates/books.html new file mode 100644 index 0000000..8b332a9 --- /dev/null +++ b/ram/portal/templates/books.html @@ -0,0 +1,104 @@ +{% extends "cards.html" %} + + {% block cards %} + {% for d in data %} +
+
+ {% if d.image.all %} + {# FIXME #} + {% for r in d.image.all %} + {% if forloop.first %}Card image cap{% endif %} + {% endfor %} + {# FIXME #} + {% endif %} +
+

+ {{ d }} + {# #} +

+ {% if d.tags.all %} +

Tags: + {% for t in d.tags.all %} + {{ t.name }}{# new line is required #} + {% endfor %} +

+ {% endif %} + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Book
Authors +
    {% for a in d.authors.all %}
  • {{ a }}
  • {% endfor %}
+
Publisher{{ d.publisher }}
Language{{ d.get_language_display }}
Pages{{ d.number_of_pages }}
Year{{ d.publication_year }}
+
+ {# FIXME Show all data #} + {% if request.user.is_staff %}Edit{% endif %} +
+
+
+
+ {% endfor %} + {% endblock %} + {% block pagination %} + {% if data.has_other_pages %} + + {% endif %} + {% endblock %} diff --git a/ram/portal/urls.py b/ram/portal/urls.py index 73b2355..fcc07a9 100644 --- a/ram/portal/urls.py +++ b/ram/portal/urls.py @@ -12,6 +12,7 @@ from portal.views import ( Manufacturers, Scales, Types, + Books, SearchRoster, ) @@ -54,6 +55,8 @@ urlpatterns = [ path("scales/", Types.as_view(), name="scales_pagination"), path("types", Types.as_view(), name="types"), path("types/", Types.as_view(), name="types_pagination"), + path("books", Books.as_view(), name="books"), + path("books/", Books.as_view(), name="books_pagination"), path( "search", SearchRoster.as_view(http_method_names=["post"]), diff --git a/ram/portal/views.py b/ram/portal/views.py index b7f56df..759a130 100644 --- a/ram/portal/views.py +++ b/ram/portal/views.py @@ -14,6 +14,7 @@ from portal.utils import get_site_conf from portal.models import Flatpage from roster.models import RollingStock from consist.models import Consist +from bookshelf.models import Book from metadata.models import Company, Manufacturer, Scale, RollingStockType, Tag @@ -340,6 +341,13 @@ class Types(GetData): self.data = RollingStockType.objects.all() +class Books(GetData): + def __init__(self): + self.title = "Books" + self.template = "books.html" + self.data = Book.objects.all() + + class GetFlatpage(View): def get(self, request, flatpage): try: