I have this model Item:
class Item(CustomBaseModel):
name = models.CharField(max_length=100)
Each item belongs to a particular category which may be a sub-category of another category. In short, categories will look like following:
Men
accessories
clothing
tops
jeans
sportswear
Women
accessories
clothing
skirt
pyjamas
sportswear
So, root categories(men, women) will have the same sub categories.
I have read many resources and tried the following:
1st Attempt:
Categories table
id | name | parent_id
1 | Men |
2 | Women |
3 | accessories | 1
4 | clothing | 1
5 | tops | 4
Problems with this approach:
I need accessories for both men and women. I will have to duplicate accessories here.
Making a query to this table will be difficult later on, in my opinion
2nd attempt:
I tried to use django-taggit. It worked just fine as tags.
Problem with this approach:
- Tags are not categories. There is no category/subcategory, parent/child relationship with tags.
What is the best way to implement this category/subcategory relationship?