I can retrieve all product based on specific category_name and Brand name, but i can not retrieve brands name based on specific category_name. How can I do this?
My Category Model
class Category(models.Model):
category_name = models.CharField(max_length=20, unique=True)
logo = models.ImageField(upload_to='Category')
slug = models.SlugField(unique="True", help_text="Slug is a field in autocomplete mode, but if you want you can modify its contents")
def __str__(self):
return self.category_name
My Brand Model
class Brand(models.Model):
brand_name = models.CharField(max_length=40, null=True, blank=True, unique=True)
def __str__(self):
return self.brand_name
My Product Model
class Product(models.Model):
product_name = models.CharField(max_length=50, blank=False, help_text='Add Product Model Name or Product Name.')
category = models.ForeignKey(Category, on_delete=models.CASCADE, default="", blank=True, related_name="Products")
brand_name = models.ForeignKey(Brand, on_delete=models.CASCADE, default="", blank=True, related_name="Products")
specification = models.CharField(max_length=400, blank=True, default="")
price = models.FloatField(blank=False, default=0.00, validators=[MinValueValidator(0.0)], help_text='Price Can not be Less than Zero.')
quantity = models.PositiveBigIntegerField(default=0)
class Meta:
unique_together = [['category', 'brand_name', 'product_name', 'specification'] ]
def __str__(self):
return self.product_name