django-konst icon indicating copy to clipboard operation
django-konst copied to clipboard

Suggestion: Make Constants iterable?

Open matthijskooijman opened this issue 5 years ago • 3 comments

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.

matthijskooijman avatar Apr 12 '20 19:04 matthijskooijman

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.

lukeburden avatar Sep 02 '20 17:09 lukeburden

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 avatar Dec 29 '20 19:12 matthijskooijman

@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.

lukeburden avatar Jan 30 '21 07:01 lukeburden