diff --git a/gallery/models/album.py b/gallery/models/album.py index 11535b6..66a7935 100644 --- a/gallery/models/album.py +++ b/gallery/models/album.py @@ -22,13 +22,18 @@ class Album(models.Model): def photos_in_album(self): return self.photos.count() + @property + def photos_views(self): + total_views = sum(self.photos.views()) + return total_views + @property def cover_url(self): if self.cover: - return self.cover.photo.url + return self.cover.photo_md.url random_cover = self.photos.order_by('-width').first() if random_cover: - return random_cover.photo.url + return random_cover.photo_md.url return static('img/placeholder.png') def clean(self): diff --git a/gallery/templates/gallery/album_detail.html b/gallery/templates/gallery/album_detail.html index c5ef5ff..cf40a25 100644 --- a/gallery/templates/gallery/album_detail.html +++ b/gallery/templates/gallery/album_detail.html @@ -1,4 +1,6 @@ {% extends "base.html" %} +{% load static %} + {% block title %} Gallery : Albums : {{ album.name }} {% endblock %} @@ -9,19 +11,48 @@
  • {{ album.name }}
  • {% endblock %} + +{% block parallax %} +{% if album.cover %} +
    +{% else %} +
    +{% endif %} +
    +
    +

    {{ album.name }}

    +

    {{ album.location }}

    +

    {{ album.album_date|date:"d.m.Y" }} • {{ album.photos_in_album }} photos

    +
    +
    +{% endblock %} + + {% block content %}

    {{ album.name }}

    - {% for photo in photos %} - - {{ photo.album.name }} - {{ photo.slug }} - - {% endfor %} + {% for photo in photos %} + + {{ photo.album.name }} - {{ photo.slug }} + + {% endfor %}
    + + {% include "./_pagination.html" %} diff --git a/gallery/templates/gallery/album_list.html b/gallery/templates/gallery/album_list.html index 5b92ae2..4439a70 100644 --- a/gallery/templates/gallery/album_list.html +++ b/gallery/templates/gallery/album_list.html @@ -19,7 +19,7 @@
    diff --git a/gallery/templates/gallery/photo_detail.html b/gallery/templates/gallery/photo_detail.html index a8b5806..d91d27a 100644 --- a/gallery/templates/gallery/photo_detail.html +++ b/gallery/templates/gallery/photo_detail.html @@ -15,10 +15,22 @@ {% block content %}
    +
    - diff --git a/gallery/views.py b/gallery/views.py index 4b89074..2f64dbb 100644 --- a/gallery/views.py +++ b/gallery/views.py @@ -33,9 +33,13 @@ class AlbumDetail(DetailView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) photos = self.object.photos.all().order_by('taken_at') + + # Pagination paginator = Paginator(photos, 30) page_number = self.request.GET.get('page') page_obj = paginator.get_page(page_number) + + # Return context['photos'] = page_obj.object_list context['page_obj'] = page_obj return context