Skip to content
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

Add support for custom django fields (#1109) #1320

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

RobertKolner
Copy link

@RobertKolner RobertKolner commented Oct 18, 2024

Motivation

Using exclusively django.db.fields.Field.get_internal_type to determine which Pydantic field to use in the built schemas makes it difficult to create custom django fields. This PR adds support for a new method get_schema_type, which allows using get_internal_type for its intended purpose (determining database column types, etc.), while at the same time allowing specifying which Pydantic schema field to use.

Concerns

  • There is of course always a possibility that the users already define get_schema_type function in their field classes. Right now there is no checks or fallbacks for this scenario.
  • The name get_schema_type is somewhat generic. I have no better ideas though.
  • Monkey-patching ninja.orm.fields.TYPES is not a great solution for future-proofing the solutions using the provided pattern to define custom fields. The should probably be an additional function in ninja.orm.fields to do this. This is no longer relevant.

Notes

I don't currently have time to test the code, but see no reason why it shouldn't work. If you want to wait, I can write proper tests in a couple of weeks.

Using exclusively `django.db.fields.Field.get_internal_type` to
determine which Pydantic field to use in the built schemas makes it
difficult to create custom django fields. This PR adds support for a new
method `get_schema_type`, which allows using `get_internal_type` for its
intended purpose (determining database column types, etc.), while at the
same time allowing specifying which Pydantic schema field to use.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants