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