Child/parent hierarchy queries

Skip to first unread message

Richard Jackson

Nov 21, 2020, 3:46:36 PM11/21/20
to Mezzanine Users
Hi there!

I have four models: "Encyclopedia", "Song", "Section", "Chord". In the admin panel I have set this up with Encyclopedia being parent to Song being parent to Section being parent to Chord (i.e. there's an Encyclopedia which has a bunch of Songs, each Song is made of Sections, each Section has a bunch of Chords). The admin looks like this:


1) How can I query the Song dataset to access all its child Chords? (i.e. for each Song, return a list of all Chords)

My current method is to make datasets for Songs, Sections and Chords, pass these datasets to the html file, then script the html as so:

{% for song in songs %}
    {% for section in sections %}
        {% if section.parent.title == song.title %}
            {% for chord in chords %}
                {% if chord.parent.title == section.title and chord.parent.parent.title == section.parent.title %}
                    [ do stuff ]

I'd greatly appreciate advice on better practices for this!

2) How can I query the Chord dataset to access what Song is the parent? Chord.parent gives me the full hierarchy, but I can't work out if there's a way to specifically jump up two levels (in this instance Chord is child to Section, and Section is child to Song, and Song is what I'm looking to identify).



Richard Jackson

Nov 22, 2020, 7:03:07 AM11/22/20
2) Parent two levels up can be accessed as:

for chord in chords:

You received this message because you are subscribed to a topic in the Google Groups "Mezzanine Users" group.
To unsubscribe from this topic, visit
To unsubscribe from this group and all its topics, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages