Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make StringProperty choices parameter callable to enable dynamic lookups #291

Closed
mjmare opened this issue Dec 25, 2017 · 6 comments
Closed

Comments

@mjmare
Copy link

mjmare commented Dec 25, 2017

Currently the choices parameter accepts a static list of tuples. It would be nice if one could specify a function that provides a list of tuples. This enables dynamically looking up the list of allowed values. For example the function could do a query in the database to get the allowed values.

@aanastasiou
Copy link
Collaborator

The ultimate purpose of choices is validation. The point is to constraint the possible values that an attribute can take.

It could well be that these choices are dynamic. But where would this leave batch operations? Would this mean triggering one additional query for every db operation to ensure that the attribute takes the (currently) valid value?

I wonder if this is something that can be addressed with a change in the model. That is, turn the attribute into an entity and attempt to establish a relationship with one of the existing nodes.

If I am way off the mark here, please provide a longer description so that we can see if we could turn this into a feature (?).

@mjmare
Copy link
Author

mjmare commented Feb 18, 2019

I think that providing a callable instead of a list of tuples gives a lot of flexibility. What the callable does to return its values is up to the programmer. Of course if one puts queries or other expensive calls in the callable that might impact performance negatively. Of course the negative effects could be mitigated by caching of some sort. But again, that is the responsibility of the user.
The neomodel field would only have to test whether choices is a list or a callable. So minimal impact but a lot of flexibility.

@aanastasiou
Copy link
Collaborator

@mjmare Alright, I would mark this as an "enhancement" at the moment but I think that it would be best if ause-case scenario was provided for this to see where it fits within the bigger picture.

What do you think?

@mjmare
Copy link
Author

mjmare commented May 5, 2019

Hi @aanastasiou, I wouldn't know what to add beyond what I've written above.
The callable would get its values from elsewhere (config file, query, calculated) created a dynamic list of choices. The dynamic list might be exposed to the user in select fields. The user selects a value, which is sent to the server, where a node is validated by neomodel (by using the callable).

@aanastasiou
Copy link
Collaborator

@mjmare I am sorry I am picking this up so late. I see what you mean. This has been added to the Wiki already.

@mjmare
Copy link
Author

mjmare commented Sep 22, 2019

No prob, I appreciate your efforts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants