Add Album_list & Album_detail

This commit is contained in:
Nyymix 2025-01-04 20:04:20 +02:00
parent 1a65aec740
commit bcf2c3612b
6 changed files with 75 additions and 5 deletions

View file

@ -1,6 +1,7 @@
from datetime import datetime
from django.db import models
from django.urls import reverse
from django.utils.text import slugify
# Create your models here.
@ -43,8 +44,12 @@ class Album(models.Model):
self.slug = slugify(self.name)
super(Album, self).save(*args, **kwargs)
def get_absolute_url(self):
return reverse('gallery:album_url', kwargs={'album_slug': self.slug})
class Meta:
verbose_name_plural = "Albums"
def __str__(self):
return '{}'.format(self.name)

View file

@ -0,0 +1,17 @@
{% extends "base.html" %}
<!-- Title -->
{% block title %} Gallery : Albums : {{ album.name }} {% endblock %}
<!-- Breadcrumb -->
{% block breadcrumb %}
<li><a href="{% url 'gallery:albums_url' %}">Albums</a></li>
<li>{{ album.name }}</li>
{% endblock %}
<!-- Content -->
{% block content %}
<h1>{{ album.name }}</h1>
{% endblock %}

View file

@ -0,0 +1,22 @@
{% extends "base.html" %}
<!-- Title -->
{% block title %} Gallery : Albums {% endblock %}
<!-- Breadcrumb -->
{% block breadcrumb %}
<li>Albums</li>
{% endblock %}
<!-- Content -->
{% block content %}
<ul>
{% for album in album_list %}
<li>
<a href="{{ album.get_absolute_url }}"> {{ album.name }} </a> - {{ album.album_date|date:"d.m.Y" }}
</li>
{% endfor %}
</ul>
{% endblock %}

View file

@ -5,6 +5,14 @@ from . import views
app_name = 'gallery'
urlpatterns = [
# Main page
path('', views.Main.as_view(), name='main_url'),
# Albumin yksityiskohdat:
path('albums/<path:album_slug>/', views.AlbumDetail.as_view(), name="album_url"),
# Albumien lista:
path('albums/', views.AlbumsList.as_view(), name='albums_url'),
]

View file

@ -1,8 +1,26 @@
from django.shortcuts import render
from django.views.generic import TemplateView
from django.shortcuts import get_object_or_404, redirect, render
from django.views.generic import DetailView, ListView, TemplateView
from .models import Album
# Create your views here.
class Main(TemplateView):
template_name = "gallery/main.html"
class AlbumsList(ListView):
model = Album
template_name = 'gallery/album_list.html'
queryset = Album.objects.filter(is_public=True)
ordering = ['-album_date']
class AlbumDetail(DetailView):
model = Album
template_name = 'gallery/album_detail.html'
def get_object(self, queryset=None):
return get_object_or_404(Album, slug=self.kwargs.get('album_slug'))

View file

@ -29,7 +29,7 @@
<div class="uk-navbar-left uk-margin-left">
<ul class="uk-navbar-nav">
<li><a href="{% url 'gallery:main_url' %}"><span uk-icon="camera"></span></a></li>
<li class="uk-visible@m"><a href="">Albums</a></li>
<li class="uk-visible@m"><a href="{% url 'gallery:albums_url' %}">Albums</a></li>
<li class="uk-visible@m"><a href="">Photostream</a></li>
</ul>
</div>
@ -51,7 +51,7 @@
<button class="uk-offcanvas-close" type="button" uk-close></button>
<ul class="uk-nav uk-nav-default">
<li><a href="{% url 'gallery:main_url' %}">Home</a></li>
<li><a href="">Albums</a></li>
<li><a href="{% url 'gallery:albums_url' %}">Albums</a></li>
<li><a href="">Photostream</a></li>
<li><a href="#">Contact</a></li>
{% if user.is_authenticated %}