On my template I have 2 query sets (assessment and response), I am looping though assessment to display items. I need to display items from response from within the assessment outer loop. I would like to use one of the assessment items (assessment.practice) as the attribute in the inner result loop result.(assessment.practice) Below is what I have tried
with assessment.practice as prac
prac contains value but there is not result when used with result.prac
I think we’re going to see more specific information about what you’re trying to do here. It’s going to be most helpful if you would post your view and template for us to understand the relationships between them and how you’re trying to use them.
I want to show all questions from assessment. Response contains the true/false answers to those questions. The tables are not linked via foreign key but the value of assessment.practice_id, for example, would be “XX1001”. This is the field/column name of the response. In the response the field “XX1001” value would be true/false.
So in my outer (assessment) loop where assessment.practice_id I jump into the inner (response) loop and am trying to use the value of assessment.practice_id to access the equivalent value in the response fields as response.<assessment.practice_id>
First, I wouldn’t have designed the tables this way. If a response is related to a specific question, then there should be a relationship. What you have is unnormalized data, with the possibility of your tables getting out of sync.
Either, that field holding the “XX1001” value should be an FK to the assessment with the practice_id field of the same value, or there should be a third table consisting only of the numerical PK and the “text_name” (e.g. “XX1001”) and both the assessment and response tables would have FKs to that table.
As it stands here, you can work with your structures as defined, but you’re going to need to perform your association between the two tables in the view and not in the template. For example, you could create a list of associated responses as a new field in your model, and then iterate over that list in your template. What you’re trying to do by making that comparison within the template isn’t the right way to approach this.
Understood. The redesign (with acquired knowledge lol) will address these situations. As it stands I am hoping to get a viable prototype soon, requirement creep for this prototype is what I am dealing with now lol. I might just have to hard code in the meantime. Thanks again Ken!