django-konst
django-konst copied to clipboard
Suggestion: Make Constants iterable?
I think it would be useful if the Constants class would be iterable (iterating all constants, not groups). This would allow things like:
for c in Apple.colours:
...
I'm running into this when creating testcases where I want to test every choice for a given field.
What already works, is iterating over Apple.colours.constants, but that feels like using an undocumented internal detail, and is also unneccesarily verbose I think.
I like how that reads - feel like putting together a PR? :) If it's low-impact I'd be happy to include that.
Note that you also have by_value and by_id dicts with the constants that can already be used.
I like how that reads - feel like putting together a PR? :) If it's low-impact I'd be happy to include that.
Thanks for your response! I would like to submit a PR, but there's only so little time... I'll try, but it won't be until I start working on my Django project again, which might be a few more months. The same holds for some of my other suggestions, where you responded similarly :-)
@matthijskooijman no worries - totally understand. I still appreciate the suggestions and shall leave this issue open. I suspect over the long-run Django or the Python language or both will make this little lib redundant, but we'll see.