Passage par les pk partout.

This commit is contained in:
Hugo LEVY-FALK 2018-01-30 23:07:08 +01:00
parent 0dafa938e8
commit 5869ec943c
4 changed files with 8 additions and 8 deletions

View file

@ -10,7 +10,7 @@ class Category(models.Model):
verbose_name="Nom de la catégorie"
)
def get_absolute_url(self):
return reverse('content:category-list', kwargs={'category_id':self.id})
return reverse('content:category-list', kwargs={'pk':self.pk})
def __str__(self):
return self.name

View file

@ -10,7 +10,7 @@ from .views import (
app_name = 'content'
urlpatterns = [
path(
'category/<int:category_id>/',
'category/<int:pk>/',
ContentCategoryList.as_view(),
name='category-list'
),

View file

@ -12,14 +12,14 @@ class ContentCategoryList(generic.ListView):
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)
pk = self.kwargs['pk']
category = get_object_or_404(Category, pk=pk)
return Content.objects.filter(category=category)
def get_context_data(self, **kwargs):
context = super(generic.ListView, self).get_context_data(**kwargs)
category_id = self.kwargs['category_id']
category = get_object_or_404(Category, id=category_id)
pk = self.kwargs['pk']
category = get_object_or_404(Category, pk=pk)
context['category'] = category
return context

View file

@ -17,12 +17,12 @@
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
{% for c in categories %}
{% if category.id == c.id %}
{% if category.pk == c.pk %}
<li class="active">
{%else%}
<li>
{%endif%}
<a href="{% url 'content:category-list' category_id=c.id %}">{{c.name}}
<a href="{% url 'content:category-list' c.pk %}">{{c.name}}
</a></li>
{% endfor %}
<li><a href="{% url 'vote:home' %}">Vote</a></li>