Friday, May 21, 2021

Re: django utils Integrity error

would you lhelp with this please
am trying to paginate but its not working and i think its because of the warning
local variable 'products' is not used 
def store(request):
category = request.GET.get('Category')
if category is None:
products = Product.objects.order_by('-category').filter(is_published=True)
page_num = request.GET.get("page")
paginator = Paginator(products, 2)
try:
products = paginator.page(page_num)
except PageNotAnInteger:
products = paginator.page(1)
except EmptyPage:
products = paginator.page(paginator.num_pages)
else:
products = Product.objects.filter(category__name=category)

data = cartData(request)

cartItems = data['cartItems']

categories = Category.objects.all()

products = Product.objects.order_by('-category').filter(is_published=True)
context = {'products': products, 'cartItems': cartItems, 'categories': categories}
return render(request, 'store/store.html', context)

On Fri, 21 May 2021 at 12:22, Peter Kirieny <kirienypeter@gmail.com> wrote:
hanks but ita was already solved

On Wed, 19 May 2021 at 15:52, Antonis Christofides <antonis@antonischristofides.com> wrote:

Could you show the full error message?

Antonis Christofides  +30-6979924665 (mobile)
On 19/05/2021 02.36, Peter Kirieny wrote:
am adding class category in the models.py and adding it as a foreign key in the products model but i get this error while migrating
somebody, please help
here is the code
class Category(models.Model):      name = models.CharField(max_length=50)        def __str__(self):          return self.name      class Product(models.Model):      name = models.CharField(max_length=200)      category = models.ForeignKey(Category, on_delete=models.CASCADE)      price = models.FloatField()      digital = models.BooleanField(default=False, null=True, blank=True)      image = models.ImageField(null=True, blank=True)        def __str__(self):          return self.name
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAL8t8eqJsenwOmJA%3DO_pdcb8Vk4KnjSijoiUNe5H%3DRpPO6%3D32A%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a3b0ab19-e675-fdeb-04f2-274f2018988b%40antonischristofides.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAL8t8epdnDv0DnZ0qNDBi979qiC0zv8giJ0f6uoa0xDpQt3wFQ%40mail.gmail.com.

No comments:

Post a Comment