Comments (4)
Ah, yeah forgot about the schema, will check how to add this info with choices and if/how support enum field. Thanks for the idea!
from ormar.
Added in 0.9.1 with #93
As for now choices
appear in schema and in OpenApi schema - it's easier than defining all variants of Enums
(depending on the field type) and it's more intuitive to use in my opinion.
You can always use Enum
and pass it to choices as you already described. Updated the docs in this regard.
choices
use the same schema options as actual Enum
so should be intuitive and easy to use by API consumers in fastapi
.
from ormar.
Actually it's the other way around. It's used in pydantic only, but since you cannot set the value on ormar
model you cannot save it in database through ormar.
Choices adds pydantic validator to the model and that's why it should work with fastapi too (don't remember if tested this specifically).
from ormar.
AFAICT, I don't see the enum options in FastAPI's OpenAPI spec when I provide a choices list. The choices validator does fire after submitting a payload. It's also possible I'm just using it wrong - do you happen to have a working case with FastAPI?
Making use of Pydantic enums fed to FastAPI does a good job of informing the frontend of available options. So it would be really great to have this as feature.
from ormar.
Related Issues (20)
- Getting `KeyError` when using `.exclude` in a `QuerySetProxy`
- Migrate to Pydantic V2 HOT 14
- use snake case for table names in the database
- Multiple reverse relations not working.
- Add `first_or_none`
- FastpAPI state has not database HOT 4
- How to configure alembic autogenerate with multiple model files HOT 5
- Error awaiting None
- Upgrade to SQLAlchemy 2.0 HOT 5
- Add SELECT DISTINCT feature to queryset
- Failing test: test_weakref_init
- Reverse relation not returned from get_pydantic
- Low performance on select_all() call HOT 1
- Nullable ForeignKey field does not get updated to null
- The future of ORMAR HOT 6
- Support specifying a table comment
- Please support pydantic-2.x HOT 3
- New release with the latest dependency upgrades HOT 2
- Unresolved attribute reference 'objects'
- Model field types and pyright
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ormar.