django utils Integrity error

26 views
Skip to first unread message

Peter Kirieny

unread,
May 18, 2021, 7:37:21 PM5/18/21
to django...@googlegroups.com
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

Antonis Christofides

unread,
May 19, 2021, 8:53:02 AM5/19/21
to django...@googlegroups.com

Could you show the full error message?

Antonis Christofides
+30-6979924665 (mobile)
--
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...@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.

Peter Kirieny

unread,
May 21, 2021, 5:23:51 AM5/21/21
to django...@googlegroups.com
hanks but ita was already solved

Peter Kirieny

unread,
May 21, 2021, 5:25:34 AM5/21/21
to django...@googlegroups.com
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)
Reply all
Reply to author
Forward
0 new messages