django-ninja
django-ninja copied to clipboard
Improves create_schema to get types from custom_fields
Related to #335, #694, #764
Removes the need to update TYPES for fields passed as custom_fields.
Example:
class CustomField(models.fields.Field):
pass
class TestModel(models.Model):
custom = CustomField()
CustomType = TypeVar("CustomType")
# before
TYPES.update({'CustomField': CustomType})
Schema1 = create_schema(TestModel, custom_fields=[("custom", CustomType, ...)])
# with this PR
Schema1 = create_schema(TestModel, custom_fields=[("custom", CustomType, ...)])
Hi @lucasrcezimbra
Thank you for PR
Maybe it's also make sense to add some builtin method like "register_field_type("CustomField", MyPydanticType) that will update TYPES
and then error message should suggest to use this function ?
Maybe it's also make sense to add some builtin method like "register_field_type("CustomField", MyPydanticType) that will update TYPES
and then error message should suggest to use this function ?
Makes sense. I'll add it to this PR.