diff --git a/content/migrations/0001_initial.py b/content/migrations/0001_initial.py
index b279fa6..2ba9dba 100644
--- a/content/migrations/0001_initial.py
+++ b/content/migrations/0001_initial.py
@@ -1,4 +1,4 @@
-# Generated by Django 2.0.1 on 2018-01-14 18:04
+# Generated by Django 2.0.1 on 2018-01-24 10:29
from django.db import migrations, models
import django.db.models.deletion
@@ -24,9 +24,10 @@ class Migration(migrations.Migration):
name='Content',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
- ('Nom du contenu', models.CharField(max_length=255)),
- ('URL du contenu', models.URLField(editable=False)),
- ('group_owner', models.ForeignKey(editable=False, on_delete=django.db.models.deletion.CASCADE, to='auth.Group')),
+ ('name', models.CharField(max_length=255, verbose_name='Nom du contenu')),
+ ('content_url', models.URLField(null=True, verbose_name='URL du contenu')),
+ ('category', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='content.Category', verbose_name='Catégorie')),
+ ('group_owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='auth.Group')),
],
),
]
diff --git a/content/models.py b/content/models.py
index 9e10cf5..915fb3a 100644
--- a/content/models.py
+++ b/content/models.py
@@ -14,14 +14,19 @@ class Content(models.Model):
"""Un contenu du site (vidéo)."""
name = models.CharField(
max_length=255,
- name="Nom du contenu"
+ verbose_name="Nom du contenu"
)
group_owner = models.ForeignKey(
Group,
on_delete=models.CASCADE,
- editable=False,
)
content_url = models.URLField(
- name='URL du contenu',
- editable=False,
+ verbose_name='URL du contenu',
+ null=True,
+ )
+ category = models.ForeignKey(
+ Category,
+ on_delete=models.SET_NULL,
+ verbose_name="Catégorie",
+ null=True
)
diff --git a/content/templates/content/content_list.html b/content/templates/content/content_list.html
new file mode 100644
index 0000000..cb7827f
--- /dev/null
+++ b/content/templates/content/content_list.html
@@ -0,0 +1,17 @@
+{% extends "base.html" %}
+{% block content %}
+
+{% if category %}
+
{{category.name}}
+{% else %}
+Liste des contenus
+{% endif %}
+
+{% for content in contents %}
+
+{% endfor %}
+{% endblock %}
diff --git a/content/urls.py b/content/urls.py
new file mode 100644
index 0000000..7d45c33
--- /dev/null
+++ b/content/urls.py
@@ -0,0 +1,11 @@
+from django.urls import path
+
+from .views import ContentCategoryList
+
+urlpatterns = [
+ path(
+ 'category//',
+ ContentCategoryList.as_view(),
+ name='category-list'
+ ),
+]
diff --git a/content/views.py b/content/views.py
index 91ea44a..3fbd97e 100644
--- a/content/views.py
+++ b/content/views.py
@@ -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
diff --git a/site_tps/urls.py b/site_tps/urls.py
index dd0d9e5..0edf049 100644
--- a/site_tps/urls.py
+++ b/site_tps/urls.py
@@ -14,11 +14,12 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
-from django.urls import path
+from django.urls import include, path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home),
+ path('content/', include('content.urls')),
]
diff --git a/vote/migrations/0001_initial.py b/vote/migrations/0001_initial.py
index 70e1f19..9257673 100644
--- a/vote/migrations/0001_initial.py
+++ b/vote/migrations/0001_initial.py
@@ -1,4 +1,4 @@
-# Generated by Django 2.0.1 on 2018-01-24 09:37
+# Generated by Django 2.0.1 on 2018-01-24 10:29
from django.conf import settings
import django.core.validators
@@ -12,8 +12,8 @@ class Migration(migrations.Migration):
dependencies = [
('auth', '0009_alter_user_last_name_max_length'),
- ('content', '0002_content_category'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ('content', '0001_initial'),
]
operations = [