From cbc33c005efbc46f6b5835a137c77f050602fa97 Mon Sep 17 00:00:00 2001 From: Hugo LEVY-FALK Date: Tue, 30 Jan 2018 19:54:01 +0100 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation=20de=20Cat=C3=A9gories=20par=20fo?= =?UTF-8?q?rmulaire.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- content/models.py | 3 +++ content/templates/content/category_form.html | 7 +++++++ content/urls.py | 10 +++++++++- content/views.py | 6 +++++- templates/base.html | 2 ++ templates/nav_bar.html | 1 + 6 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 content/templates/content/category_form.html diff --git a/content/models.py b/content/models.py index f1f56ef..0ef0972 100644 --- a/content/models.py +++ b/content/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.urls import reverse from django.contrib.auth.models import Group @@ -8,6 +9,8 @@ class Category(models.Model): max_length=255, verbose_name="Nom de la catégorie" ) + def get_absolute_url(self): + return reverse('content:category-list', kwargs={'category_id':self.id}) class Content(models.Model): diff --git a/content/templates/content/category_form.html b/content/templates/content/category_form.html new file mode 100644 index 0000000..3d86f22 --- /dev/null +++ b/content/templates/content/category_form.html @@ -0,0 +1,7 @@ +{% extends 'base.html' %} +{% block content %} +
{% csrf_token %} + {{ form.as_p }} + +
+{% endblock %} diff --git a/content/urls.py b/content/urls.py index 78f290c..f25f420 100644 --- a/content/urls.py +++ b/content/urls.py @@ -1,6 +1,9 @@ from django.urls import path -from .views import ContentCategoryList +from .views import ( + ContentCategoryList, + CreateCategory, +) app_name = 'content' urlpatterns = [ @@ -9,4 +12,9 @@ urlpatterns = [ ContentCategoryList.as_view(), name='category-list' ), + path( + 'category/new/', + CreateCategory.as_view(), + name='category-new' + ), ] diff --git a/content/views.py b/content/views.py index 3fbd97e..980720d 100644 --- a/content/views.py +++ b/content/views.py @@ -1,4 +1,4 @@ -from django.views.generic import ListView +from django.views.generic import ListView, CreateView from django.shortcuts import get_object_or_404 from .models import Content, Category @@ -21,3 +21,7 @@ class ContentCategoryList(ListView): category = get_object_or_404(Category, id=category_id) context['category'] = category return context + +class CreateCategory(CreateView): + model = Category + fields = '__all__' diff --git a/templates/base.html b/templates/base.html index 61edb79..acbbf5f 100644 --- a/templates/base.html +++ b/templates/base.html @@ -9,7 +9,9 @@ {% include 'nav_bar.html' %} +
{% block content %}{% endblock %} +
diff --git a/templates/nav_bar.html b/templates/nav_bar.html index f79d7a1..1eb5f93 100644 --- a/templates/nav_bar.html +++ b/templates/nav_bar.html @@ -26,6 +26,7 @@ {% endfor %}
  • Vote
  • +
  • Nouvelle catégorie