-
Notifications
You must be signed in to change notification settings - Fork 177
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
Adding GeneratedField to supported types for RangeNumericFilter #824
base: main
Are you sure you want to change the base?
Conversation
What type is GeneratedField in database? |
depends on what you pass for |
if the column type is variable, how we are checking if this field can be used for numeric filtering? |
One way we can resolve this is to make sure the output_field of the GeneratedField is one of the already supported field types (DecimalField, IntegerField, FloatField, AutoField) |
exactly, if you can, please update the PR |
Sure, working on that now |
please ensure that your change is going to be backward compatible as well. I guess on django pre 5.x import fill fail. |
what is the best appraoch you suggest for safe importing? I thought either importing only if django is >=5.0 at the top level, or do the whole importing the GeneratedField.output_field checks inside a try-except and handling the ImportError if raised. |
In the past I used the approach below but if you are aware of something more elegant, I'm open to incorporate it everywhere: https://github.com/unfoldadmin/django-unfold/blob/main/src/unfold/admin.py#L59-L65 |
I don't think my appraoch is more elegant, but just might be more "local"
Tell me which you prefer and I'll implement it |
Your snippet looks good as well. |
Please take a look at the final code when you have the time :) |
I played with simpler check for backward compatibility. What do you think about the solution below. Would you mind to test it? if not isinstance(
field.output_field if hasattr(field, "output_field") else field,
(DecimalField, IntegerField, FloatField, AutoField),
):
raise TypeError(
f"Class {type(self.field)} is not supported for {self.__class__.__name__}."
) |
I have a use case where I wish to have a RangeNumericFilter for a GeneratedField.
This was not allowed until now. This PR is to allow this configuration.
I had not added any extra validations to check whether the actual value of the GeneratedField is numeric, as I don't think this should be done by unfold. Let me know if you think otherwise.