Django - How do i include several elements in pagination
<p>This is my first project in django and I've been following several different tutorial, most of which are very useful. I've made a very simple blog as my first app and now I'm expanding it a bit beyond what the tutorials have shown me. Namely, I added new model, Category, which every post can belong to. The model itself and all related stuff works. The only thing that I'm now having problem with is resolving URLs. I'm using pagination to normally list posts, but I would like to add additional and optional element to it, namely category. So when browsing through the list I not only have the options of <code>site.com/posts/?page=2</code> but can also use something like <code>site.com/posts/?cat=news&amp;page=2</code></p>

<p><strong>models.py</strong></p>

<pre><code># Model for blog post category
class Category(models.Model):
    title = models.CharField(max_length=120)
    slug = models.SlugField(unique=True)
    description = models.TextField()

    class Meta:
        verbose_name_plural = "Categories"

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse("posts:detail", kwargs={"slug": self.slug})
# Model for blog post
class Post(models.Model):
    title = models.CharField(max_length=120)
    slug = models.SlugField(unique=True)
    category = models.ManyToManyField(Category, blank=True, through='CategoryToPost')
    content = models.TextField()
    image = FilerImageField(null=True, blank=True, related_name="post_image")
    created = models.DateTimeField(auto_now=False, auto_now_add=True)
    published = models.DateTimeField(auto_now=False, auto_now_add=True)
    updated = models.DateTimeField(auto_now=True, auto_now_add=False)

    def __str__(self):
        return self.title

    def Category(self):
        return self.category.all()

    def get_absolute_url(self):
        return reverse("posts:detail", kwargs={"slug": self.slug})
# Model for assigning post to a category
class CategoryToPost(models.Model):
    post = models.ForeignKey(Post)
    category = models.ForeignKey(Category)
</code></pre>

<p><strong>urls.py</strong></p>

<pre><code>from .views import (
    post_list,
    post_detail
    )

urlpatterns = [
    url(r'^$', post_list),
    url(r'^(?P&lt;slug&gt;[\w-]+)/$', post_detail, name='detail'),
]
</code></pre>

<p>Note on urls, the line from project urls.py is <code>url(r'^posts/', include("posts.urls", namespace='posts')),</code></p>

<p><strong>views.py</strong></p>

<pre><code>def post_detail(request, slug):

    instance = get_object_or_404(Post, slug=slug)

    context = {
        "title": instance.title,
        "instance": instance,
    }

    return render(request, "post_single.html", context)

def post_list(request):

    queryset_list = Post.objects.all().order_by("-published")
    paginator = Paginator(queryset_list, 5)

    page = request.GET.get('page')
    try:
        queryset = paginator.page(page)
    except PageNotAnInteger:
        queryset = paginator.page(1)
    except EmptyPage:
        queryset = paginator.page(paginator.num_pages)

    context = {
        "title": "Post List",
        "object_list": queryset,
    }

    return render(request, "post_list.html", context)
</code></pre>

<p>I know that I need to add this somewhere inside post_list, but to be honest I'm not even sure where to start and django pagination documentation isn't very clear on this.</p>