I'm unsure of the best way to design my models for this task. Searching around suggests that I need to use something like Django-MPTT.
I am creating a listings application where any 'item' can be listed under multiple categories. From any category I will need to be able to query for 'items' that match.
An example should illustrate what I want a little better.
I have one Item1 that is to be assigned to two sub categories.
TopLevel1
--- Sublevel1
--- Sublevel2
-----> Item1
TopLevel1
--- Sublevel1
------> Item1
--- Sublevel2
Can anyone suggest how the models/relationships should be constructed? My current implementation
class Category(models.Model):
name = models.CharField(max_length=128, blank=False)
parent = models.ForeignKey('self', null=True, blank=True)
class Item(TimeStampedModel):
name = models.TextField(null=False, blank=False)
categories = models.ManyToManyField(Category)
Does not feel like the correct solution?