diff --git a/gallery/models.py b/gallery/models.py index 2e35bab..95af69e 100644 --- a/gallery/models.py +++ b/gallery/models.py @@ -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) + diff --git a/gallery/templates/gallery/album_detail.html b/gallery/templates/gallery/album_detail.html new file mode 100644 index 0000000..7f7f5b6 --- /dev/null +++ b/gallery/templates/gallery/album_detail.html @@ -0,0 +1,17 @@ +{% extends "base.html" %} + + +{% block title %} Gallery : Albums : {{ album.name }} {% endblock %} + + +{% block breadcrumb %} +
  • Albums
  • +
  • {{ album.name }}
  • +{% endblock %} + + +{% block content %} + +

    {{ album.name }}

    + +{% endblock %} \ No newline at end of file diff --git a/gallery/templates/gallery/album_list.html b/gallery/templates/gallery/album_list.html new file mode 100644 index 0000000..85ae62e --- /dev/null +++ b/gallery/templates/gallery/album_list.html @@ -0,0 +1,22 @@ +{% extends "base.html" %} + + +{% block title %} Gallery : Albums {% endblock %} + + +{% block breadcrumb %} +
  • Albums
  • +{% endblock %} + + +{% block content %} + +{% endblock %} \ No newline at end of file diff --git a/gallery/urls.py b/gallery/urls.py index dbde1a4..81403d9 100644 --- a/gallery/urls.py +++ b/gallery/urls.py @@ -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//', views.AlbumDetail.as_view(), name="album_url"), + + # Albumien lista: + path('albums/', views.AlbumsList.as_view(), name='albums_url'), + ] diff --git a/gallery/views.py b/gallery/views.py index e5a2e27..e76f363 100644 --- a/gallery/views.py +++ b/gallery/views.py @@ -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" \ No newline at end of file + 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')) \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index b9dadec..340e317 100644 --- a/templates/base.html +++ b/templates/base.html @@ -29,7 +29,7 @@
    @@ -51,7 +51,7 @@