-
-
Notifications
You must be signed in to change notification settings - Fork 494
need DATETIME_FORMAT to ninja Schema #1451
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
Comments
django-ninja>=1.4.1,
|
|
|
@LeonemZhang you can apply global json encoder for all dates/datetimes like this: from ninja.renderers import JSONRenderer
from ninja.responses import NinjaJSONEncoder
class JsonEncoder(NinjaJSONEncoder):
def default(self, o):
if isinstance(o, datetime):
return o.strftime('%Y-%m-%dT%H:%M:%S')
return super().default(o)
class CustomJsonRender(JsonRenderer):
encoder_class = JsonEncoder
...
api = NinjaAPI(renderer=CustomJsonRender()) |
Thanks, it works |
@LeonemZhang yes - JSONRenderer is the one! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I hope to add a global configuration to modify the format of the datetime return
The text was updated successfully, but these errors were encountered: