Browse Source

Add Photo view

master
Nyymix 1 month ago
parent
commit
7dd4ccb6bf
  1. 11
      gallery/templates/gallery/photo_detail.html
  2. 18
      gallery/templates/gallery/photo_list.html
  3. 2
      gallery/urls.py
  4. 1
      gallery/views/__init__.py
  5. 20
      gallery/views/photo.py
  6. 2
      templates/_header.html

11
gallery/templates/gallery/photo_detail.html

@ -0,0 +1,11 @@
{% extends "base.html" %}
{% block title %}Albums : {{ photo.album.name }} / {{ photo.slug }} {% endblock %}
{% block content %}
<h2>{{ photo.slug }}</h2>
<p><img src="{{ photo.photo.url }}" alt="{{ photo.slug }}" /></p>
{% endblock %}

18
gallery/templates/gallery/photo_list.html

@ -0,0 +1,18 @@
{% extends "base.html" %}
{% block title %}{{ photo.album.name }}{% endblock %}
{% block content %}
<h2>Album: {{ photo.album.name }}</h2>
<ul>
{% for photo in photo_list %}
<li>
<a href="{% url 'gallery:photo_url' album_slug=photo.album.slug photo_slug=photo.slug %}">{{ photo.album.name }} - {{ photo.slug }}</a>
</li>
{% endfor %}
</ul>
{% endblock %}

2
gallery/urls.py

@ -9,10 +9,12 @@ app_name = 'gallery'
urlpatterns = [
path('', views.Main.as_view(), name='main_url'),
path('photostream/', views.PhotosList.as_view(), name='photos_url'),
path('galleries/', views.GalleriesList.as_view(), name='galleries_url'),
path('galleries/<slug:gallery_slug>/', views.GalleryDetail.as_view(), name='gallery_url'),
path('albums/', views.AlbumsList.as_view(), name='albums_url'),
path('albums/<albumname:album_slug>/', views.AlbumDetail.as_view(), name="album_url"),
path('albums/<albumname:album_slug>/<filename:photo_slug>', views.PhotoDetail.as_view(), name='photo_url'),
path('tags/', views.TagsList.as_view(), name='tags_url'),
path('tags/<slug:tag_slug>/', views.TagDetail.as_view(), name="tag_url"),
]

1
gallery/views/__init__.py

@ -1,4 +1,5 @@
from .main import *
from .gallery import *
from .album import *
from .photo import *
from .tag import *

20
gallery/views/photo.py

@ -0,0 +1,20 @@
from django.shortcuts import render
from django.views.generic import DetailView, ListView
from ..models import Photo
### PHOTO LIST ###
class PhotosList(ListView):
model = Photo
queryset = Photo.objects.filter(album__public=True,).order_by("-taken_at")
paginate_by = 5
### PHOTO DETAIL ###
class PhotoDetail(DetailView):
model = Photo
slug_url_kwarg = 'photo_slug'
paginate_by = 5
def get_queryset(self):
return Photo.objects.filter(slug=self.kwargs['photo_slug'], album__slug=self.kwargs['album_slug'],)

2
templates/_header.html

@ -3,7 +3,7 @@
<div class="uk-navbar-left">
<ul class="uk-navbar-nav">
<li class="uk-active"><a href="{% url 'gallery:main_url' %}"><span uk-icon="camera"></span></a></li>
<li><a class="uk-text-large" href="#">Photostream</a></li>
<li><a class="uk-text-large" href="{% url 'gallery:photos_url' %}">Photostream</a></li>
<li><a class="uk-text-large" href="{% url 'gallery:albums_url' %}">Albums</a></li>
<li><a class="uk-text-large" href="{% url 'gallery:galleries_url' %}">Galleries</a></li>
<li><a class="uk-text-large" href="{% url 'gallery:tags_url' %}">Tags</a></li>

Loading…
Cancel
Save