alkali icon indicating copy to clipboard operation
alkali copied to clipboard

Another field type CategoryList

Open hpca01 opened this issue 5 years ago • 6 comments

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?

hpca01 avatar Mar 10 '19 21:03 hpca01

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.

kneufeld avatar Mar 10 '19 23:03 kneufeld

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?

hpca01 avatar Mar 11 '19 02:03 hpca01

I think the api should be ChoicesField.__init__(choices, *args, **kw).

kneufeld avatar Mar 11 '19 13:03 kneufeld

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!

hpca01 avatar Mar 15 '19 15:03 hpca01

Did you have a merge request or something you want me to take a look at?

kneufeld avatar Mar 18 '19 19:03 kneufeld

Whoops, I apologize, here is the PR Link

For the test cases I planned on doing:

  1. List with str only
  2. Dict with str only
  3. Empty list
  4. Empty dict
  5. List with mixed types
  6. Dict with mixed types

Should I test other things as well?

hpca01 avatar Mar 18 '19 19:03 hpca01