alkali
alkali copied to clipboard
Another field type CategoryList
Hi, We spoke earlier about a proposal to add another field, CategoryList.
It can be seen as a set of unique values that can be validated against at run time to make sure the correct data is being held there. I checked out the SetField field on alkali, but it doesn't seem to include a way to pass allowable choices as the only choices available.
Specs:
- User uses
fields.CategoryList
to call an instance and passes it a list or dict. - Override cast so that when user tries to initialize the model w/ values that are not in the aforementioned iterable they get a error stating that they can only save allowed pieces of information.
Would you be interested?
That sounds pretty reasonable but I'm not nuts about the name. What about FixedSetField
or ChoicesField
. I'm leaning towards ChoicesField
as that more closely matches what's in Django.
No worries, lol sorry I usually work with an EHR record system that calls it's choices fields CategoryList
.
I think it's better to do it with ChoicesField
like you said. With that in mind, would you support adding allowed_choices
in the self._properties
of the Field class?
I think the api should be ChoicesField.__init__(choices, *args, **kw)
.
Just added in code, took a while to figure out edge test cases. Although I did my testing on Ipython, I will write out test cases in your fields_tests.
Let me know if you want the formatting revised or certain pieces to be moved around. I am still a newbie dev lol.
Thanks again!
Did you have a merge request or something you want me to take a look at?
Whoops, I apologize, here is the PR Link
For the test cases I planned on doing:
- List with
str
only - Dict with
str
only - Empty list
- Empty dict
- List with mixed types
- Dict with mixed types
Should I test other things as well?