I want when am adding the products in the django admin, when I enter the category of the product to list only the subcategories belonging only to the category.
Here is my models
class Category(models.Model):
category_name = models.CharField(max_length=50)
slug = models.SlugField(max_length=100, unique=True)
category_image = models.ImageField(upload_to =
'photos/categories', blank = True)
created_at = models.DateTimeField(auto_now_add=True)
class Sub_Category(models.Model):
category = models.ForeignKey(Category, on_delete=models.CASCADE)
sub_category_name = models.CharField(max_length=50)
slug = models.SlugField(max_length=100, unique=True)
In my admin area I want the subcategory to be filtered from the category when adding different products.... Like showing say Furniture(category) to show chairs, beds (subcategories)
class Product(models.Model):
category = models.ForeignKey(Category, on_delete=models.CASCADE)
sub_category = models.ForeignKey(Sub_Category, on_delete=models.CASCADE)
product_name = models.CharField(max_length = 200, unique=True)
slug = models.SlugField(max_length=200, blank=True)
description = models.TextField(max_length = 1000)
price = models.IntegerField()
discount_price = models.IntegerField(blank=True)
on_offer = models.BooleanField(default=False)