-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Add support for grouped choices. #3108
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
Conversation
This also adds support for mixing single and paired choices: ``` [ ('poor', 'Poor quality'), 'medium', ('good', 'Good quality'), ] ```
Looking good, there's just a few tests failing for Django 1.4 / Python 2.6. Other than that, I think we could with |
A utility makes more sense, I will amend it and look at the 1.4 tests. |
else: | ||
self.choices = OrderedDict([(item, item) for item in choices]) | ||
flat_choices = [flatten_choice(c) for c in choices] | ||
self.choices = OrderedDict(list(itertools.chain(*flat_choices))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be leaving the .choices
attribute alone, but adding a .flatchoices
attribute?
What's the right way for us to access the grouping information, if we need to (eg for displaying a grouped select in the browsable API)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Irrespective of my comment above - this would be an improvement either way, so it's possible we should accept this, and consider any further enhancements seperately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, it seems likely to an issue that we have lost the group information. I suspect that keeping the .choices
flat will reduce further refactoring. How about about adding a new .choices_list
property that stores the choices list, that was originally passed in?
Do you wan't me to make any changes to this? I looked into using For the following grouped choices:
We could have something like:
For non-grouped choices the My concern is that most places (including the templates) would need to be updated to use Since the grouped choices appears to be a bit broken currently, I guess this will not break existing usage. |
Thanks for all your work on this @maxpeterson! I've picked this up, and completed the work required for rendering these in templates too. Now in #3225 and to be released as part of 3.2.0. Nice work 😄 |
@tomchristie thanks, glad it was of use. |
Closes #1533.
This also adds support for mixing single and paired choices (which may not be desirable):