You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not really an issue, more like a beginner of a solution for those who rack their brains on how how programmatically setup filters in different situations.
My need is this one: I'm using a JSONField to store data according to what the user specified in a configuration. It means I can't know in advance what are the "subfields" inside the json.
Model example:
class MyModel(models.Model):
name = models.CharField()
data = JSONField()
Now, I didn't do a benchmark. I'm sure it can quickly become an abyss with too many lookup expressions and data fields. But with some more logic to not add all the lookup expressions, it should be ok.
This discussion was converted from issue #1553 on January 24, 2023 09:11.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello there,
Not really an issue, more like a beginner of a solution for those who rack their brains on how how programmatically setup filters in different situations.
My need is this one: I'm using a JSONField to store data according to what the user specified in a configuration. It means I can't know in advance what are the "subfields" inside the json.
Model example:
What's inside the data could be something like:
And it's always the same in all objects.
As I want to be able to filter such a field, I'm setting up a FilterSet with a custom method and add some logic in the constructor as such:
FilterSet
Viewset
I can now filter as such:
Now, I didn't do a benchmark. I'm sure it can quickly become an abyss with too many lookup expressions and data fields. But with some more logic to not add all the lookup expressions, it should be ok.
Hope it helps.
Beta Was this translation helpful? Give feedback.
All reactions