Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 878191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:44:04+00:00 2026-05-15T11:44:04+00:00

I’m writing entries for cross-browser bugs/workarounds. I would like the main view to present

  • 0

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()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T11:44:05+00:00Added an answer on May 15, 2026 at 11:44 am

    You don’t need a specific third table. Django’s ManyToManyField – which is what you want here for the relationship between Entires and Categories – automatically takes care of the joining table, unless you specifically want to control it (eg if you need to store extra data on the join).

    As you recognise in your comment, django-mptt is the best bet for storing the hierarchical relationship of categories. Once you’ve done that, there’s nothing particularly difficult in the fact that you have a ManyToMany relationship between entries and categories – you would just need to show a separate tree for every category the entry is in:

    {% for category in my_entry.categories.all %}
        {{ category.show_tree }}
    {% endfor %}
    

    where show_tree is the method that draws the tree for that category – which you’d need to define, along the lines of the answer to your last question.

    Edit

    The main issue with the models as you have them now is that there are no relationships. At the very least, you’ll need a ManyToMany relationship between Bug and Category, and a ForeignKey relationship from Category to itself (ie from one category to itself). Adding MPTT onto the Category model on top of that – via level, tree_id, left and right fields which will be added automatically by django-mptt – will make it easier to get all parents or children in one go.

    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)
        categories = models.ManyToManyField('Category')
    
    class Category ( models.Model ):
        name = models.CharField( max_length=100 )
        parent = models.ForeignKey('self', null=True, blank=True, related_name='children')
    
    mptt.register(Category)
    

    Now, given a single Bug element, you can get its associated categories with mybug.categories.all(), and for each category you can get its ancestors with category.get_ancestors(). See the mptt docs for more things you can do, especially the provided template tags for showing trees.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.