Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ilykos opened this issue Jun 13, 2024 · 0 comments

Comments

@ilykos
Copy link

ilykos commented Jun 13, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant