i have products and i made their prices to be different base on the color and sizes here is the code
class MyProductAttribute(models.Model):
products = models.ForeignKey(Product, on_delete=models.CASCADE)
size = models.ForeignKey(Size,on_delete=models.CASCADE)
color = models.ForeignKey(Color,on_delete=models.CASCADE)
main_price = models.DecimalField( max_digits=5, decimal_places=2, null=True)
def __str__(self):
return self.products.title```
now i want to filter all product that have d same color same as prices too.
this is my product model
```class Product(models.Model):
category = models.ForeignKey('Category', related_name='product', on_delete=models.CASCADE)
created_by = models.ForeignKey(User, related_name='product_user', on_delete=models.CASCADE)
# size = models.ForeignKey(Size, on_delete=models.CASCADE, null=True)
# color = models.ForeignKey(Color, on_delete=models.CASCADE, null=True)
title = models.CharField( max_length=50)
main_price = models.DecimalField( max_digits=5, decimal_places=2, null=True)
description = models.TextField(blank=True)
information = models.TextField(blank=True, null=True)
image = models.ImageField( upload_to='images/', default='images/default.png', null=True)
image2 = models.ImageField( upload_to='images/', default='images/default.png', null=True)
image3 = models.ImageField( upload_to='images/', default='images/default.png', null=True)
slug = models.SlugField(max_length=255)
slashed_price = models.DecimalField( max_digits=5, decimal_places=2, null=True)
in_stalk = models.BooleanField(default=True)
in_active = models.BooleanField(default=True)
in_trending = models.BooleanField(default=True, null=True)
just_arrived = models.BooleanField(default=True, null=True)
created = models.DateTimeField( auto_now_add=True)
updated = models.DateTimeField(auto_now=False, null=True)
# objects = models.Manager()
# products = ProductManager()
class Meta:
verbose_name_plural = 'Products'
ordering = ('-created','-updated')
def __str__(self) :
return self.title```
and this is the color and size
```class Color(models.Model):
name = models.CharField(max_length=200, null=True)
color_code = models.CharField(max_length=200, null=True)
def __str__(self):
return self.name
class Size(models.Model):
title = models.CharField(max_length=200, null=True)
def __str__(self):
return self.title```
and this is my views
```def filter_product(request):
colors = request.GET.getlist('color[]')
allProduct = Product.objects.all()
allProduct = allProduct.filter(myproductattribute__color__id__in = colors)
print(allProduct, 'oooooooooooooooooooooooooooooooooooooooooo')
return render(request, 'ajax/product-list.html', {'data':allProduct})
please i need help