Skip to content

Somewhat effective way of using values() #340

@rrauenza

Description

@rrauenza

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().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions