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
Describe the bug
Django-ninja uses get_internal_type to determine field type for schemas. This works with all of the default fields, but does not work with custom fields. For fields that don't define it, Django will return self.__class__.__name__. For fields that define a custom get_internal_type or db_type, the type parsed by django-ninja might not necessarily be correct.
For example, I have a custom field that stores data in the database as a string, but converts that string to a bool when the data is read from the database. Since get_internal_type returns CharField, django-ninja generates a schema with string, while ideally it would be a bool.
This is fixable by adding annotations for schemas using these custom fields, but it would be nice to have a solution on the field level. The code in get_schema_field gets the field type like this:
Describe the bug
Django-ninja uses
get_internal_type
to determine field type for schemas. This works with all of the default fields, but does not work with custom fields. For fields that don't define it, Django will returnself.__class__.__name__
. For fields that define a customget_internal_type
ordb_type
, the type parsed by django-ninja might not necessarily be correct.For example, I have a custom field that stores data in the database as a string, but converts that string to a bool when the data is read from the database. Since
get_internal_type
returnsCharField
, django-ninja generates a schema withstring
, while ideally it would be a bool.This is fixable by adding annotations for schemas using these custom fields, but it would be nice to have a solution on the field level. The code in
get_schema_field
gets the field type like this:I'd propose changing it to this:
That would let a user define
get_python_type
on the custom field. If this is something you'd be interested in I can make the change.Versions (please complete the following information):
The text was updated successfully, but these errors were encountered: