Forum Discussion

TimothyJames's avatar
TimothyJames
Frequent Visitor
4 years ago

Dynamically Merging Different Tables - Sub querying

Hello, we have a django web application that is utilizing content types and generic foreign keys, and if you're unfamiliar with that, essentially. Its a referential lookup on other tables. 

 

So in this example, I have merged together a few tables to represent this table structure, only showing relevant columns for complexities sake.

 

lookuptable (first row is formulas)

 

formulas being applied  merged in from django_contenttype using utilized_model_idmerged in from django_contenttype using utilized_model_idconcat("public ", app_label, "_", model)
idutilized_model_object_idutilized_model_idapp_labelmodellookuptable
14112aqeidareapublic aqe_idarea
25112aqeidareapublic aqe_idarea
36112aqeidareapublic aqe_idarea
47112aqeidareapublic aqe_idarea
58112aqeidareapublic aqe_idarea
36911354corelookuplookupcheckoutsectionpublic corelookup_lookupcheckoutsection

 

 

 

django_contenttype

idapp_labelmodel
1biqarea
2biqbuilding
112aqeidarea
354corelookuplookupcheckoutsection

 

 

aqe_idarea

idareanamearea rollup
4TM northtransmissions
5TM Southtransmissions
6TM north2transmissions
7tm south2transmissions
8TM south5transmissions

 

 

What I want to do is merge into the lookuptable the dynamic lookup from the related django_contenttypes with a subquery.

 

The resulting table would look like lookuptable, but it would have aqe_idarea.areaname and aqe_idarea.area rollup on rows 1 - 5, but then it would do the lookup for corelookup_lookupcheckoutsection.[column N's name] on row 3691.

 

 

How do I do this in the advanced query editor to essentially sub query for each row?

1 Reply

  • I'm unsure that I'm understanding correctly. Can you explicitly show what the final result should look like for the given example?