django-polymorphic
django-polymorphic copied to clipboard
Somewhat effective way of using values()
I wonder if you might want to document this alternative when using values()? Even though this isn't really django-polymorphic specific, I think you're the one adding in the ctype.
In this example, we have A->B->C and A->D->E
E has a column 'foo', and C has a column 'bar'.
This works by joining in the model name from the ctype. Then also joining in the specific attributes of the inherited models ...
A.objects.values('polymorphic_ctype__model', 'b__c__foo', 'd__e__bar')
One could look at the model string returned instead of isinstance and then select which fields to look at in the code. The irrelevant ones end up being None.
...maybe this is obvious, but it was kind of an Aha! moment for me when trying to convert some queries to values().
Thanks a lot! This is actually not obvious at all
@neoden My 5 years older self now doesn't remember why I added this -- I didn't state what problem I was solving!