B
B
bolatkenebayev2015-02-07 12:16:03
Django
bolatkenebayev, 2015-02-07 12:16:03

Pagination in django?

models.py
class Category(models.Model):
name = models.CharField(max_length=150, default="", blank=False, verbose_name="Category")
title = models.CharField(max_length=200,default="" , blank=False, verbose_name="Title")
meta_desc = tinymce_models.HTMLField(max_length=200,default="", blank=True, verbose_name="Short Description")
def __unicode__(self):
return self.name
class Meta:
verbose_name_plural = "Categories"
verbose_name = "Category"
class Product(models.Model):
name = models.CharField(max_length=150, default="", blank=False, verbose_name="Name")
category = models.ForeignKey(Category , related_name='cat', blank=False)
title = models.CharField(max_length=200,default="", blank=False, verbose_name="Title")
short_text = models.CharField(max_length =200,default="", blank=False, verbose_name="Short description")
full_text = tinymce_models.HTMLField(max_length=300,default="", blank=True, verbose_name="Long description")
price = models.DecimalField (max_digits=10, decimal_places=2,verbose_name="Price", blank=False,null=True)
def __unicode__(self):
return self.title
class Meta:
verbose_name_plural = "Products"
verbose_name = "Product"
views.py
from django.core.paginator import Paginator
def catalog(request, article_id=1,page_number=1):
all_product = Product.objects.filter(category_id=article_id)
current_page = Paginator(all_product, 10)
return render_to_response('catalog.html',{'catalog': current_page. page(page_number)})
url.py
url(r'^catalog/get/(?P\d+)/$', 'project.views.catalog'),
url(r'^/page/(\d+)/ $', 'project.views.catalog1'),
catalog.html


  • {% if catalog.has_previous %}
  • previous
    {% endif %}
    {% for page in catalog.paginator.page_range %}
    {% if page == catalog.number %}
  • {{ page }}
    {% else %}
  • {{ page }}
    {% endif %}
    {% endfor %}
    {% if catalog.has_next %}
  • next
    {% endif %}

Look here pagination is not working

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question