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

Expose Sorting Function #78

Open
FlorianWendelborn opened this issue Mar 13, 2019 · 1 comment
Open

Expose Sorting Function #78

FlorianWendelborn opened this issue Mar 13, 2019 · 1 comment

Comments

@FlorianWendelborn
Copy link

In the case I’m currently working on, I don’t know (and have no easy way to retrieve) all CSV headers in advance. It’d be great if this library would expose an overridable def sort_headers method.

@C0DK
Copy link

C0DK commented Jul 14, 2019

or simply choose whether to sort the headers or not. For me it seems weird that you want alphabetically ordered fields, but it's fair if some people want that - but why not make it based on the serializer as the rest of DRF does? so if you want them alphabetical order, then you simply order them alphabetically in the serializer.

It's really difficult to change the fields in the viewset currently. Currently i am doing:

def get_renderer_context(self):
        context = super().get_renderer_context()
        # force the order from the serializer.
        context['header'] = self.serializer_class.Meta.fields
        return context

But that is really hacky (and seems weird that i have to force it to do the 'default'. Also this was problematic (the code above) when i went to change fields dynamically in the serializer making the seperation of responsibilities really difficult.

TL;DR Please just remove the ordering and/or make a function where you can PICK to choose to sort them alphabetically. I can make a PR if neeeded be that fixes this, but i would prefer that it is merged if i spend time creating it.

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

2 participants