2

I'm working on a template that renders a list of product. I want the user to filter the content based on the properties of the product.

Those are my models : """ Coutries, regions and cities tables """

class Country(models.Model):
    name = models.CharField(max_length=200)


class Region(models.Model):
    name = models.CharField(max_length=200)
    country = models.ForeignKey(
        Country,
        on_delete=models.CASCADE)

class City(models.Model):
    name = models.CharField(max_length=200)
    region = models.ForeignKey(
        Region,
        on_delete=models.CASCADE)

""" Categories and their subcategories tables """

class Category(models.Model):
    name = models.CharField(max_length=200)

class Subcategory(models.Model):
    name = models.CharField(max_length=200)
    Subcategory = models.ForeignKey(
        Category,
        on_delete=models.CASCADE)

""" Product Table """

class Product(models.Model):
    name = models.CharField(max_length=200)
    Description = models.TextField()

""" Products Location tables """

class ProductLocation(models.Model):
    Address = models.CharField(max_length=200)
    country = models.ForeignKey(
        Country,
        on_delete=models.CASCADE)
    region = models.ForeignKey(
        Region,
        on_delete=models.CASCADE)
    city = models.ForeignKey(
        City, 
        on_delete=models.CASCADE)
    product = models.ForeignKey(
        Product,
        on_delete=models.CASCADE)

""" Products Classification """

class ProductClassification(models.Model):

    category = models.ForeignKey(
        Category,
        on_delete=models.CASCADE)

    subcategory = models.ForeignKey(
        Subcategory,
        on_delete=models.CASCADE)

    product = models.ForeignKey(
        Product,
        on_delete=models.CASCADE)

In the page i will have 3 inputs for location : - Country, Region and City. I think I should implement a Dependent/Chained Dropdown I want to filter the products by country, region and city.

In another 2 inputs (Checkbox to select multiple choice) the user can select the category and subcategory to filter the products concerned.

How can I implement this ? I think That I will need Ajax and Json rendering. But I wasn't able to find a proper way to do it.

GuardianAngel
  • 103
  • 1
  • 7

0 Answers0