-
-
Notifications
You must be signed in to change notification settings - Fork 392
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
choices
Field Support
#1078
Comments
(Actually I quickly came to realize that it may not be feasible with modifying |
I have observed the same issue, I think the solution here is to use Pydantic's Enum option as described here with ModelSchema. |
Yeah, it works when you manually set it. But I feel like ModelSchema should automatically pick this up. |
I noticed the same issue. Setting it manually works, but it'd be nice if it did it automatically. Also, how can I make it display the "label" instead of the "value" of the For example:
When setting the field in the schema manually - |
To be honest I totally agree this is something that should be automatically detected from the Django field choices. It is really weird that is not happening already :( |
This looks like it would have had some trouble until Django 5, because Django 4 and below required you to pass in your choices using the .choices property ex. |
I noticed that Django-ninja doesn't support some fields with
choices
when converted withModelSchema
. Is there a reason why Django-ninja doesn't support these fields?Also, I haven't yet tried, but is it feasible to extract the
choices
from the model and create a customTYPES
fromninja/orm/fields.py
, like done here #694 (comment) .Below is an example of
choices
not being picked up.The resulting
TestSchema
and the openapi schema does not recognize theTextChoices
set as the field for selection, and will only set it as a string field. It will pick it up if we manually set a field like below.Btw, I love using your Django-ninja! It makes using Django for rest apis so much easier.
The text was updated successfully, but these errors were encountered: