jazzband / jazzband/django-model-utils
Retrieve choices by group
- Dominant language
- Python
- Stars
- 2.8k
- Forks
- 374
- PR merge metrics
- No merged PRs in 30d
Description
When I create a Choices object with option groups, like this:
` STATUS = Choices(('visible', ['new', 'archived']), ('invisible', ['draft', 'deleted']))`
I'd like to be able to retrieve a subset Choices object (or any iterable) by passing the group label, like this:
```
STATUS.visible
# output: Choices('new', 'archived')
'new' in STATUS.visible
# output: True
```
I can kind of achieve this with the following code:
```
for ch in STATUS:
STATUS._identifier_map[ch[0]] = Choices(*ch[1])
```
Could this feature be integrated in the class?
Contributor guide
Research direction
Locate the Choices class and inspect how option groups and identifier lookup are currently represented. Define the expected behavior for STATUS.visible and membership in the returned subset, then check the existing Choices tests before adding coverage for grouped retrieval.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100