Création de Catégories par formulaire.
This commit is contained in:
parent
29ad08df0f
commit
cbc33c005e
6 changed files with 27 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.urls import reverse
|
||||||
from django.contrib.auth.models import Group
|
from django.contrib.auth.models import Group
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,6 +9,8 @@ class Category(models.Model):
|
||||||
max_length=255,
|
max_length=255,
|
||||||
verbose_name="Nom de la catégorie"
|
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):
|
class Content(models.Model):
|
||||||
|
|
7
content/templates/content/category_form.html
Normal file
7
content/templates/content/category_form.html
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{% extends 'base.html' %}
|
||||||
|
{% block content %}
|
||||||
|
<form action="" method="post">{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
<input type="submit" value="Sauvegarder" />
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
|
@ -1,6 +1,9 @@
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from .views import ContentCategoryList
|
from .views import (
|
||||||
|
ContentCategoryList,
|
||||||
|
CreateCategory,
|
||||||
|
)
|
||||||
|
|
||||||
app_name = 'content'
|
app_name = 'content'
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
@ -9,4 +12,9 @@ urlpatterns = [
|
||||||
ContentCategoryList.as_view(),
|
ContentCategoryList.as_view(),
|
||||||
name='category-list'
|
name='category-list'
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
'category/new/',
|
||||||
|
CreateCategory.as_view(),
|
||||||
|
name='category-new'
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -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 django.shortcuts import get_object_or_404
|
||||||
|
|
||||||
from .models import Content, Category
|
from .models import Content, Category
|
||||||
|
@ -21,3 +21,7 @@ class ContentCategoryList(ListView):
|
||||||
category = get_object_or_404(Category, id=category_id)
|
category = get_object_or_404(Category, id=category_id)
|
||||||
context['category'] = category
|
context['category'] = category
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
class CreateCategory(CreateView):
|
||||||
|
model = Category
|
||||||
|
fields = '__all__'
|
||||||
|
|
|
@ -9,7 +9,9 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{% include 'nav_bar.html' %}
|
{% include 'nav_bar.html' %}
|
||||||
|
<div class="container">
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
|
</div>
|
||||||
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
|
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
|
||||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
</a></li>
|
</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<li><a href="">Vote</a></li>
|
<li><a href="">Vote</a></li>
|
||||||
|
<li><a href="{% url 'content:category-new' %}">Nouvelle catégorie</a></li>
|
||||||
<li class="dropdown">
|
<li class="dropdown">
|
||||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
|
|
Loading…
Reference in a new issue