There is such a dictionary:
{'Junior': {'Shoes': set(), 'Accessories': set()}, 'Men': {'Shoes': {'New Balance', 'Asics', 'adidas', 'Nike', 'Saucony', 'Jordan Brand', 'Puma', 'Reebok Classic'}, 'Accessories': {'socks', 'Hats', 'bags'}}, 'Women': {'Shoes': {'Converse', 'Reebok Classic', 'adidas', 'Nike'}, 'Accessories': {'backpacks'}}} Which is generated here by such a dictionary generator:
q = Products.query genders = q.filter(Products.gender !=0).group_by(Products.gender) categories = q.filter(Products.category != 0, Products.category != 'Clothing').group_by(Products.category).all() gen = {gender.gender: {category.category: {subcategory.subcategory for subcategory in q.filter(Products.gender == gender.gender, Products.category == category.category, Products.subcategory != 0).group_by(Products.subcategory)} for category in categories} for gender in genders} I'm not sure that the generator is written correctly, but it works almost as it should.
I tried to use #gen = defaultdict(lambda:None,gen) but then I realized that it works according to a different principle.
The fact is that in the database there are really no elements satisfying the selection condition (filter), so this is the picture {'Junior': {'Shoes': set(), 'Accessories': set()}
Such a dictionary can not be parsed, nor lead to JSON, again, because of set()
The task is to write None or False instead of set ().