Устранение неполадок динамического обновления изображений и цветовой фильтрации на странице продукта DjangoPython

Программы на Python
Anonymous
Устранение неполадок динамического обновления изображений и цветовой фильтрации на странице продукта Django

Сообщение Anonymous »


I have created a hyperlink in html So, In product_detail_page.html:

Color {% for c in colors %} {% endfor %} Now it is taking colors id (suppose if I click on red color it is taking {?colorID=1} in url)

Now I created a view for this That if I Click in a color it will change the product Image So, In views.py

def product_detail_view(request,pid): product=Product.objects.get(pid=pid) colors = Color.objects.all() sizes= Size.objects.all() p_image=product.p_images.all() products=Product.objects.filter(cagtegory=product.cagtegory) ColorID=request.GET.get('colorID') if ColorID: product=Product.objects.filter(color=ColorID) else: product=Product.objects.all() context={ "p":product, "p_image":p_image, 'colors': colors, 'sizes': sizes, 'products': products, } return render(request,"core/product_detail.html",context) and I created this models in models.py

class Product(models.Model): pid=ShortUUIDField(length=10,max_length=100,prefix="prd",alphabet="abcdef") user=models.ForeignKey(CustomUser, on_delete=models.SET_NULL ,null=True) cagtegory=models.ForeignKey(Category, on_delete=models.SET_NULL ,null=True,related_name="category") vendor=models.ForeignKey(Vendor, on_delete=models.SET_NULL,null=True,related_name="product") color=models.ManyToManyField(Color,blank=True) size=models.ManyToManyField(Size,blank=True) title=models.CharField(max_length=100,default="Apple") image=models.ImageField(upload_to=user_directory_path,default="product.jpg") description=models.TextField(null=True, blank=True,default="This is a product") price = models.DecimalField(max_digits=10, decimal_places=2, default=1.99) old_price = models.DecimalField(max_digits=10, decimal_places=2, default=2.99) specifications=models.TextField(null=True, blank=True) product_status=models.CharField(choices=STATUS, max_length=10,default="In_review") status=models.BooleanField(default=True) in_stock=models.BooleanField(default=True) featured=models.BooleanField(default=False) digital=models.BooleanField(default=False) sku=ShortUUIDField(length=10,max_length=100,prefix="sku",alphabet="abcdef") date=models.DateTimeField(auto_now_add=True) updated=models.DateTimeField(null=True,blank=True) class Meta: verbose_name_plural="Products" def product_image(self): return mark_safe('
Изображение
'%(self.image.url)) def __str__(self): return self.title def get_percentage(self): new_price=((self.old_price-self.price)/self.old_price)*100 return new_price class ProductImages(models.Model): images=models.ImageField(upload_to="product-image",default="product.jpg") product=models.ForeignKey(Product,related_name="p_images" ,on_delete=models.SET_NULL ,null=True) color = models.ForeignKey(Color, on_delete=models.CASCADE) date=models.DateTimeField(auto_now_add=True) class Meta: verbose_name_plural="Product Images" I created these two models But It is not working I mean, it is not changing the color as per the ColorID Please help me out!!!


Источник: https://stackoverflow.com/questions/780 ... ango-produ

Вернуться в «Python»