Skip to content

Feature proposal: Allow providing dicts to fieldnames for downstream renaming #159

Open
@ilykos

Description

@ilykos

In many occasions, name of distant cousin table fields like driver__vehicle__part__manufacturer can be too verbose and hard to manage. I often find myself renaming these to a more convenient name, but that requires chaining an additional rename on top of the result.

I suggest allowing user to supply a name mapping as a dict() where keys() are used in the regular to_dataframe fashion, while items() are used as columns= value for renaming, before the dataframe is returned. Here's what it would look like

# user code 
fieldname_dict = {
    "driver__vehicle__part__manufacturer": "part_manufacturer"
}

Model.objects.to_dataframe(fieldnames=fieldname_dict)

# inside `to_dataframe`
...
return qs.to_dataframe().rename(columns=fieldname_dict)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions