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

Use OrderedDict for RelatedField.choices. #2408

Closed
kylemacfarlane opened this issue Jan 13, 2015 · 5 comments
Closed

Use OrderedDict for RelatedField.choices. #2408

kylemacfarlane opened this issue Jan 13, 2015 · 5 comments

Comments

@kylemacfarlane
Copy link

kylemacfarlane commented Jan 13, 2015

The order of choices is useful when returning metadata. For ChoiceFields DRF uses an OrderedDict but for RelatedFields everything is put into a regular dict which loses order.

https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/relations.py#L106

@tomchristie
Copy link
Member

tomchristie commented Jan 13, 2015

Sure, don't see why not.

@tomchristie tomchristie changed the title Shouldn't RelatedField.choices use OrderedDict? Use OrderedDict for RelatedField.choices. Jan 13, 2015
@tomchristie tomchristie added this to the 3.0.4 Release milestone Jan 13, 2015
@aidanlister
Copy link

aidanlister commented May 14, 2015

This breaks all my unit tests! Should this be documented somewhere? http://share.aidanlister.com/ayni

@tomchristie
Copy link
Member

tomchristie commented May 15, 2015

@aidanlister dict comparisons against ordered dict still return true if the elements match. Any chance you've missed something unexpected (eg some of the values are subtly different, or you're needlessly performing a comparison of the repr() of the compared items or something)

@xordoquy
Copy link
Collaborator

xordoquy commented May 15, 2015

IIRC the comparison display is not really usefull with Python 2.7. With Python3 I think it appears as a dict

@aidanlister
Copy link

aidanlister commented May 17, 2015

Ah @tomchristie I think you're right, the change is how the dates are presented in DRF3.

(Pdb) print response.data['results'][0]['updated']
2015-05-17T12:16:36.529346Z
(Pdb) print expected['results'][0]['updated']
2015-05-17T12:16:36.529346+00:00

I'll see what I can work out

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

No branches or pull requests

5 participants