I have tried this a lot and searched about it too but not found any solution, I want that in admin panel when admin selects the category choice field and the subcategory choice field changes according to it, like I have a category called 'Shoes' and 'watches' and sub-category accordingly for shoes - 'puma', 'Adidas' and watches-'titan', 'G-shock'. when admin selects category 'shoes' subcategory choices should be 'puma' and 'Adidas' and if he/she selects category 'watches' subcategory choices should be 'titan' and 'G-shock'.
here is my models.py
from django.db import models
from django.db import connection
# Create your models here.
class categorie(models.Model):
name = models.CharField(max_length=100, unique=True)
def __str__(self):
return self.name
class sub_categorie(models.Model):
sub_name = models.CharField(max_length=100)
catagory_name = models.ForeignKey(categorie, on_delete=models.CASCADE, default=1)
def __str__(self):
return self.sub_name
class Products(models.Model):
Product_Name = models.CharField(max_length=100)
price = models.FloatField()
Description = models.TextField()
ctg = models.ForeignKey(categorie, on_delete=models.CASCADE,blank = False, default=1)
sub_category = models.ForeignKey(sub_categorie, on_delete=models.CASCADE,blank = False)