7 changed files with 68 additions and 13 deletions
@ -0,0 +1,17 @@ |
|||||
|
{% extends "base.html" %} |
||||
|
{% block content %} |
||||
|
|
||||
|
{% if category %} |
||||
|
<h1>{{category.name}}</h1> |
||||
|
{% else %} |
||||
|
<h1>Liste des contenus</h1> |
||||
|
{% endif %} |
||||
|
|
||||
|
{% for content in contents %} |
||||
|
<div> |
||||
|
<h2>{{content.name}}</h2> |
||||
|
<h3>Contenu proposé par {{content.group_owner.name}}</h3> |
||||
|
<a href="{{content.content_url}}">C'est ici que ça se passe</a> |
||||
|
</div> |
||||
|
{% endfor %} |
||||
|
{% endblock %} |
||||
@ -0,0 +1,11 @@ |
|||||
|
from django.urls import path |
||||
|
|
||||
|
from .views import ContentCategoryList |
||||
|
|
||||
|
urlpatterns = [ |
||||
|
path( |
||||
|
'category/<int:category_id>/', |
||||
|
ContentCategoryList.as_view(), |
||||
|
name='category-list' |
||||
|
), |
||||
|
] |
||||
@ -1,3 +1,23 @@ |
|||||
from django.shortcuts import render |
from django.views.generic import ListView |
||||
|
from django.shortcuts import get_object_or_404 |
||||
|
|
||||
# Create your views here. |
from .models import Content, Category |
||||
|
|
||||
|
|
||||
|
class ContentCategoryList(ListView): |
||||
|
"""Affiche les contenus d'une catégorie.""" |
||||
|
model = Content |
||||
|
context_object_name = "contents" |
||||
|
template_name = "content/content_list.html" |
||||
|
|
||||
|
def get_queryset(self): |
||||
|
category_id = self.kwargs['category_id'] |
||||
|
category = get_object_or_404(Category, id=category_id) |
||||
|
return Content.objects.filter(category=category) |
||||
|
|
||||
|
def get_context_data(self, **kwargs): |
||||
|
context = super(ListView, self).get_context_data(**kwargs) |
||||
|
category_id = self.kwargs['category_id'] |
||||
|
category = get_object_or_404(Category, id=category_id) |
||||
|
context['category'] = category |
||||
|
return context |
||||
|
|||||
Loading…
Reference in new issue