I'm writing entries for cross-browser bugs/workarounds. I would like the main view to present a hierarchial tree starting with the primary categories and descending into more specific categories:
css
layout
float
position
specificity
js
dom
html
object
embed
Let's say I want to file an entry and have it show up under both float
and position
because the bug in this entry is a combination of the two.
My category schema is as such:
category_id category_name parent_id
With that, my float
row would be:
10 float 9
9
( parent_id ) points to my layout
row:
9 layout 8
8
points to my css
row:
8 css null
Question 1
: Since entries can potentially have many categories, I need a table to map those relationships, right? I currently have an Entries and Categories model, so I'd need a third table? It would contain the category_id
and the entry_id
.
Question 2:
How can I preserve a tree/hierarchial view of the categories if I'm doing many categories to one entry? I'm a bit confused because initially it seemed a little easier with one category but since I have multiple I'm confused as to how I would even begin this.
Models so far:
class Bug( models.Model ):
name = models.CharField( max_length=100 )
slug = models.SlugField(unique=True)
excerpt = models.TextField()
excerpt_markdown = models.TextField( editable=False, blank=True )
summary = models.TextField()
summary_markdown = models.TextField(editable=False, blank=True)
#workaround = models.TextField()
#workaround_markdown = models.TextField(editable=False, blank=True)
date_added = models.DateTimeField()
poster = models.ForeignKey(User)
class Category ( models.Model ):
name = models.CharField( max_length=100 )
parent_id = models.IntegerField()