I have an ugly loop that is operating as a band-aid in Django that I'd like to optimize into a join. I've broken it down to the most basic structure to help simplify the problem. I'm hoping someone else has run into something like this before -- if not, I'll share the answer when I finally fix it.I have an ugly loop that is operating as a band