Before sqlmodel I used pydantic modle as input and output Schema . But now i m switched with the sqlmodel but i have some issue , some field(like password) that i don,t want to gave to the user in output schema how it will be restricted:
See original GitHub issueFirst Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn’t find it.
- I searched the SQLModel documentation, with the integrated search.
- I already searched in Google “How to X in SQLModel” and didn’t find any information.
- I already read and followed all the tutorial in the docs and didn’t find an answer.
- I already checked if it is not related to SQLModel but to Pydantic.
- I already checked if it is not related to SQLModel but to SQLAlchemy.
Commit to Help
- I commit to help with one of those options 👆
Example Code
class Book(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
title: str
description: str
Description
Before sqlmodel I used pydantic modle as input and output Schema . But now i m switched with the sqlmodel but i have some issue , some field(like password) that i don,t want to gave to the user in output schema how it will be restricted:
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.6
Python Version
3.9.5
Additional Context
No response
Issue Analytics
- State:
- Created a year ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Multiple Models with FastAPI - SQLModel - tiangolo
We have been using the same Hero model to declare the schema of the data we receive in the API, the table model...
Read more >Using SQLAlchemy ORM, Pydantic and Alembic
One thing that I am running into however, is when I want to add a single column to a table I need to...
Read more >SQLModel: SQL DBs based on Python type hints. The ...
SQLModel is a library for interacting with SQL DBs, based on Python type hints. Each model is both a Pydantic and SQLAlchemy model, ......
Read more >SQLModel: The New ORM for FastAPI and Beyond Transcript
I don't know for sure I'm asking you, but it seems to me, looking in from the outside that SQL model was something...
Read more >See raw diff
I don't know what I'd use it for, but I'm sure there'd be some kind of use out there. ... you can give...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Maypher has it right. There’s a more expanded example in the tutorial, with a base class and what would be here a UserCreate class to define the fields required in a POST call to create such an entity etc. https://sqlmodel.tiangolo.com/tutorial/fastapi/multiple-models/
If you mean returning a table without some fields you could do something like this. Let’s say you have a users table
You want to return the user data without the password (id and name only) so you could do this
Depending on the framework you are using the method might change. I’m assuming you are using FastAPI as your backend. You can use the
response_model
parameter to filter out unwanted parameters.What this does is it gets the user from the database and when returning, it filters out all the fields that aren’t present in the model you passed to
response_model
. Here’s more info about the topic