Open jmduke opened 1 year ago
You could write your own logic to parse data in an alternate format. a JSON string or list of JSON strings seem to be the easiest. See here for some examples.
Alternatively if there's a fixed set of possible values for filters, you could define your own schema dynamically using pydantic's create_model. I've written a filter decorator that does this here
Thank you for the links @OtherBarry! It seems like the escape hatch I really want is something like fastapi's Depends
— if I'm understanding it correctly, it lets me declare an arbitrary Request → obj
mapping and pass it into the view function. Does Django-ninja have any such similar construct?
The dependency injection aspect of FastAPI was intentionally excluded from Django Ninja, so there's nothing directly equivelant.
There's a few ways to do it:
pre=True
validators) you can do all sorts of things to coax the data into the format you want. The only issue is that the auto-generated openapi schema might not line up with how the data needs to be inputted.Thank you! (I ended up going with the last option.)
@jmduke Would you care to share your code? I'm in a similar situation and don't really know where to begin.
(I suspect this is related to https://github.com/vitalik/django-ninja/issues/86.)
I want to implement arbitrary key/value filtering. A toy example of this:
This doesn't appear to work out of the box, and I've tried various different approaches. I suspect the issue is because the 'key' presented to django-ninja is
metadata[foo]
, but I can't actually figure out where to plug into the framework to override the translation of the query parameters into the parsed input that's passed to the Schema. Any guidance? Thanks!