views:

220

answers:

1

Here's where I'm exposed as the fraud of a programmer I am.

I've never created a data tree.

Basically, I have a table with four fields: A, B, C, and D. I need to create a tree of unordered lists based on these fields. Ultimately, it would look something like this:

  • A1
    • B1
      • C1
        • D1
        • D2
      • C2
        • D3
        • D4
    • B2
      • C2
        • D5
        • D6
      • C3
        • D7
        • D8
  • A2
    • B2
      • C1
        • D9
        • D10
      • C4
        • D11
        • D12
    • B3
      • C3
        • D13
        • D14
      • C4
        • D15
        • D16

It's a pretty basic, 4-level tree...I think. It is much larger and complex than I'm representing here, but that's enough to get the point across.

I'm hoping to keep it to one database call, but I'm not sure if that's possible.

I'll be fetching the data with a Django QuerySet. I have Python at my disposal.

I don't even know where to start with the programming logic to keep it from becoming unwieldy.

I'd appreciate any pointers, guidance, links...just about anything!

+5  A: 

I am not sure of your question, is there something specific you are asking?

Here are a few reusable applications for storing hierarchical data:

What's your reasoning behind using the 4 separate fields?

Gerry
+1 for mptt - I've never used treebeard, but no doubt that's good too.
Daniel Roseman
mptt is just what I needed. Thank you!
cpharmston