models.py
class Category(models.Model):
name = models.CharField(max_length=150, default="", blank=False, verbose_name="Категория")
title = models.CharField(max_length=200,default="", blank=False, verbose_name="Заголовок")
meta_desc = tinymce_models.HTMLField(max_length=200,default="", blank=True, verbose_name="Краткое описание")
def __unicode__(self):
return self.name
class Meta:
verbose_name_plural = "Категории"
verbose_name = "Категория"
class Product(models.Model):
name = models.CharField(max_length=150, default="", blank=False, verbose_name="Название")
category = models.ForeignKey(Category , related_name='cat', blank=False)
title = models.CharField(max_length=200,default="", blank=False, verbose_name="Заголовок")
short_text = models.CharField(max_length=200,default="", blank=False, verbose_name="Краткое описание")
full_text = tinymce_models.HTMLField(max_length=300,default="", blank=True, verbose_name="Полное описание")
price = models.DecimalField(max_digits=10, decimal_places=2,verbose_name="Цена", blank=False,null=True)
def __unicode__(self):
return self.title
class Meta:
verbose_name_plural = "Товары"
verbose_name = "Товар"
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 %}
Посмотрите здесь не работает пагинация