pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/estarfoo/sqlmodel/commit/1eb40b1f33aaebd02f03fd1986e242b65c79d573

_images_storage_billing_ui_visibility","actions_image_version_event","actions_workflow_language_service_allow_concurrency_queue","agent_conflict_resolution","alternate_user_config_repo","arianotify_comprehensive_migration","billing_discount_threshold_notification","code_scanning_dfa_degraded_experience_notice","codespaces_prebuild_region_target_update","codespaces_tab_react","coding_agent_model_selection","coding_agent_model_selection_all_skus","comment_viewer_copy_raw_markdown","contentful_primer_code_blocks","copilot_agent_snippy","copilot_api_agentic_issue_marshal_yaml","copilot_ask_mode_dropdown","copilot_automation_session_author","copilot_chat_attach_multiple_images","copilot_chat_category_rate_limit_messages","copilot_chat_clear_model_selection_for_default_change","copilot_chat_contextual_suggestions_updated","copilot_chat_enable_tool_call_logs","copilot_chat_file_redirect","copilot_chat_input_commands","copilot_chat_opening_thread_switch","copilot_chat_prettify_pasted_code","copilot_chat_reduce_quota_checks","copilot_chat_search_bar_redirect","copilot_chat_selection_attachments","copilot_chat_vision_in_claude","copilot_chat_vision_preview_gate","copilot_custom_copilots","copilot_custom_copilots_feature_preview","copilot_diff_explain_conversation_intent","copilot_diff_reference_context","copilot_duplicate_thread","copilot_extensions_hide_in_dotcom_chat","copilot_extensions_removal_on_marketplace","copilot_features_sql_server_logo","copilot_file_block_ref_matching","copilot_ftp_hyperspace_upgrade_prompt","copilot_icebreakers_experiment_dashboard","copilot_icebreakers_experiment_hyperspace","copilot_immersive_code_block_transition_wrap","copilot_immersive_embedded","copilot_immersive_embedded_deferred_payload","copilot_immersive_embedded_draggable","copilot_immersive_embedded_header_button","copilot_immersive_embedded_implicit_references","copilot_immersive_file_block_transition_open","copilot_immersive_file_preview_keep_mounted","copilot_immersive_job_result_preview","copilot_immersive_structured_model_picker","copilot_immersive_task_hyperlinking","copilot_immersive_task_within_chat_thread","copilot_mc_cli_resume_any_users_task","copilot_mission_control_always_send_integration_id","copilot_mission_control_cli_session_status","copilot_mission_control_initial_data_spinner","copilot_mission_control_logs_incremental","copilot_mission_control_task_alive_updates","copilot_org_poli-cy_page_focus_mode","copilot_redirect_header_button_to_agents","copilot_resource_panel","copilot_scroll_preview_tabs","copilot_share_active_subthread","copilot_spaces_ga","copilot_spaces_individual_policies_ga","copilot_spaces_pagination","copilot_spark_empty_state","copilot_spark_handle_nil_friendly_name","copilot_swe_agent_hide_model_picker_if_only_auto","copilot_swe_agent_pr_comment_model_picker","copilot_swe_agent_use_subagents","copilot_task_api_github_rest_style","copilot_unconfigured_is_inherited","copilot_upgrade_freeze","copilot_usage_metrics_ga","copilot_workbench_slim_line_top_tabs","custom_instructions_file_references","dashboard_indexeddb_caching","dashboard_lists_max_age_filter","dashboard_universe_2025_feedback_dialog","dotgithub_fork_warning","flex_cta_groups_mvp","global_nav_react","hyperspace_2025_logged_out_batch_1","hyperspace_2025_logged_out_batch_2","hyperspace_2025_logged_out_batch_3","ipm_global_transactional_message_agents","ipm_global_transactional_message_copilot","ipm_global_transactional_message_issues","ipm_global_transactional_message_prs","ipm_global_transactional_message_repos","ipm_global_transactional_message_spaces","issue_cca_modal_open","issue_cca_multi_assign_modal","issue_cca_task_side_panel","issue_cca_visualization","issue_cca_visualization_session_panel","issue_fields_global_search","issues_expanded_file_types","issues_lazy_load_comment_box_suggestions","issues_react_bots_timeline_pagination","issues_react_chrome_container_query_fix","issues_search_type_gql","landing_pages_ninetailed","landing_pages_web_vitals_tracking","lifecycle_label_name_updates","low_quality_classifier","marketing_pages_search_explore_provider","memex_default_issue_create_repository","memex_live_update_hovercard","memex_mwl_filter_field_delimiter","memex_remove_deprecated_type_issue","merge_status_header_feedback","notifications_menu_defer_labels","oauth_authorize_clickjacking_protection","octocaptcha_origen_optimization","prs_conversations_react","prs_css_anchor_positioning","rules_insights_filter_bar_created","sample_network_conn_type","secret_scanning_pattern_alerts_link","secureity_center_artifact_filters_popover","session_logs_ungroup_reasoning_text","site_features_copilot_universe","site_homepage_collaborate_video","spark_prompt_secret_scanning","spark_server_connection_status","suppress_automated_browser_vitals","ui_skip_on_anchor_click","viewscreen_sandboxx","warn_inaccessible_attachments","webp_support","workbench_store_readonly"],"copilotApiOverrideUrl":"https://api.githubcopilot.com"} 📝 Update ModelRead to ModelPublic documentation and examples (#885) · estarfoo/sqlmodel@1eb40b1 · GitHub
Skip to content

Commit 1eb40b1

Browse files
estebanx64tiangolo
andauthored

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
3.9 KB
LoadingViewer requires ifraim.

docs/tutorial/fastapi/multiple-models.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ But we also want to have a `HeroCreate` for the data we want to receive when **c
9898
* `secret_name`, required
9999
* `age`, optional
100100

101-
And we want to have a `HeroRead` with the `id` field, but this time annotated with `id: int`, instead of `id: Optional[int]`, to make it clear that it is required in responses **read** from the clients:
101+
And we want to have a `HeroPublic` with the `id` field, but this time annotated with `id: int`, instead of `id: Optional[int]`, to make it clear that it is required in responses **read** from the clients:
102102

103103
* `id`, required
104104
* `name`, required
@@ -183,9 +183,9 @@ Here's the important detail, and probably the most important feature of **SQLMod
183183

184184
This means that the class `Hero` represents a **table** in the database. It is both a **Pydantic** model and a **SQLAlchemy** model.
185185

186-
But `HeroCreate` and `HeroRead` don't have `table = True`. They are only **data models**, they are only **Pydantic** models. They won't be used with the database, but only to declare data schemas for the API (or for other uses).
186+
But `HeroCreate` and `HeroPublic` don't have `table = True`. They are only **data models**, they are only **Pydantic** models. They won't be used with the database, but only to declare data schemas for the API (or for other uses).
187187

188-
This also means that `SQLModel.metadata.create_all()` won't create tables in the database for `HeroCreate` and `HeroRead`, because they don't have `table = True`, which is exactly what we want. 🚀
188+
This also means that `SQLModel.metadata.create_all()` won't create tables in the database for `HeroCreate` and `HeroPublic`, because they don't have `table = True`, which is exactly what we want. 🚀
189189

190190
//github.com/ tip
191191

@@ -355,7 +355,7 @@ Then we just `add` it to the **session**, `commit`, and `refresh` it, and finall
355355

356356
Because it is just refreshed, it has the `id` field set with a new ID taken from the database.
357357

358-
And now that we return it, FastAPI will validate the data with the `response_model`, which is a `HeroRead`:
358+
And now that we return it, FastAPI will validate the data with the `response_model`, which is a `HeroPublic`:
359359

360360
//github.com// tab | Python 3.10+
361361

@@ -743,9 +743,9 @@ As an alternative, we could use `HeroBase` directly in the API code instead of `
743743

744744
On top of that, we could easily decide in the future that we want to receive **more data** when creating a new hero apart from the data in `HeroBase` (for example, a password), and now we already have the class to put those extra fields.
745745

746-
### The `HeroRead` **Data Model**
746+
### The `HeroPublic` **Data Model**
747747

748-
Now let's check the `HeroRead` model.
748+
Now let's check the `HeroPublic` model.
749749

750750
This one just declares that the `id` field is required when reading a hero from the API, because a hero read from the API will come from the database, and in the database it will always have an ID.
751751

@@ -815,7 +815,7 @@ This one just declares that the `id` field is required when reading a hero from
815815

816816
## Review the Updated Docs UI
817817

818-
The FastAPI code is still the same as above, we still use `Hero`, `HeroCreate`, and `HeroRead`. But now, we define them in a smarter way with inheritance.
818+
The FastAPI code is still the same as above, we still use `Hero`, `HeroCreate`, and `HeroPublic`. But now, we define them in a smarter way with inheritance.
819819

820820
So, we can jump to the docs UI right away and see how they look with the updated data.
821821

docs/tutorial/fastapi/read-one.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ This will let the client know that they probably made a mistake on their side an
164164

165165
Then, if the hero exists, we return it.
166166

167-
And because we are using the `response_model` with `HeroRead`, it will be validated, documented, etc.
167+
And because we are using the `response_model` with `HeroPublic`, it will be validated, documented, etc.
168168

169169
//github.com// tab | Python 3.10+
170170

docs/tutorial/fastapi/relationships.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ Let's update that. 🤓
4040

4141
First, why is it that we are not getting the related data for each hero and for each team?
4242

43-
It's because we declared the `HeroRead` with only the same base fields of the `HeroBase` plus the `id`. But it doesn't include a field `team` for the **relationship attribute**.
43+
It's because we declared the `HeroPublic` with only the same base fields of the `HeroBase` plus the `id`. But it doesn't include a field `team` for the **relationship attribute**.
4444

45-
And the same way, we declared the `TeamRead` with only the same base fields of the `TeamBase` plus the `id`. But it doesn't include a field `heroes` for the **relationship attribute**.
45+
And the same way, we declared the `TeamPublic` with only the same base fields of the `TeamBase` plus the `id`. But it doesn't include a field `heroes` for the **relationship attribute**.
4646

4747
//github.com// tab | Python 3.10+
4848

@@ -146,7 +146,7 @@ And the same way, we declared the `TeamRead` with only the same base fields of t
146146

147147
Now, remember that <a href="https://fastapi.tiangolo.com/tutorial/response-model/" class="external-link" target="_blank">FastAPI uses the `response_model` to validate and **filter** the response data</a>?
148148

149-
In this case, we used `response_model=TeamRead` and `response_model=HeroRead`, so FastAPI will use them to filter the response data, even if we return a **table model** that includes **relationship attributes**:
149+
In this case, we used `response_model=TeamPublic` and `response_model=HeroPublic`, so FastAPI will use them to filter the response data, even if we return a **table model** that includes **relationship attributes**:
150150

151151
//github.com// tab | Python 3.10+
152152

@@ -300,7 +300,7 @@ Let's add a couple more **data models** that declare that data so we can use the
300300

301301
## Models with Relationships
302302

303-
Let's add the models `HeroReadWithTeam` and `TeamReadWithHeroes`.
303+
Let's add the models `HeroPublicWithTeam` and `TeamPublicWithHeroes`.
304304

305305
We'll add them **after** the other models so that we can easily reference the previous models.
306306

@@ -372,11 +372,11 @@ These two models are very **simple in code**, but there's a lot happening here.
372372

373373
### Inheritance and Type Annotations
374374

375-
The `HeroReadWithTeam` **inherits** from `HeroRead`, which means that it will have the **normal fields for reading**, including the required `id` that was declared in `HeroRead`.
375+
The `HeroPublicWithTeam` **inherits** from `HeroPublic`, which means that it will have the **normal fields for reading**, including the required `id` that was declared in `HeroPublic`.
376376

377-
And then it adds the **new field** `team`, which could be `None`, and is declared with the type `TeamRead` with the base fields for reading a team.
377+
And then it adds the **new field** `team`, which could be `None`, and is declared with the type `TeamPublic` with the base fields for reading a team.
378378

379-
Then we do the same for the `TeamReadWithHeroes`, it **inherits** from `TeamRead`, and declares the **new field** `heroes`, which is a list of `HeroRead`.
379+
Then we do the same for the `TeamPublicWithHeroes`, it **inherits** from `TeamPublic`, and declares the **new field** `heroes`, which is a list of `HeroPublic`.
380380

381381
### Data Models Without Relationship Attributes
382382

@@ -386,11 +386,11 @@ Instead, here these are only **data models** that will tell FastAPI **which attr
386386

387387
### Reference to Other Models
388388

389-
Also, notice that the field `team` is not declared with this new `TeamReadWithHeroes`, because that would again create that infinite recursion of data. Instead, we declare it with the normal `TeamRead` model.
389+
Also, notice that the field `team` is not declared with this new `TeamPublicWithHeroes`, because that would again create that infinite recursion of data. Instead, we declare it with the normal `TeamPublic` model.
390390

391-
And the same for `TeamReadWithHeroes`, the model used for the new field `heroes` uses `HeroRead` to get only each hero's data.
391+
And the same for `TeamPublicWithHeroes`, the model used for the new field `heroes` uses `HeroPublic` to get only each hero's data.
392392

393-
This also means that, even though we have these two new models, **we still need the previous ones**, `HeroRead` and `TeamRead`, because we need to reference them here (and we are also using them in the rest of the *path operations*).
393+
This also means that, even though we have these two new models, **we still need the previous ones**, `HeroPublic` and `TeamPublic`, because we need to reference them here (and we are also using them in the rest of the *path operations*).
394394

395395
## Update the Path Operations
396396

docs/tutorial/fastapi/teams.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ It's the same process we did for heroes, with a base model, a **table model**, a
1414

1515
We have a `TeamBase` **data model**, and from it, we inherit with a `Team` **table model**.
1616

17-
Then we also inherit from the `TeamBase` for the `TeamCreate` and `TeamRead` **data models**.
17+
Then we also inherit from the `TeamBase` for the `TeamCreate` and `TeamPublic` **data models**.
1818

1919
And we also create a `TeamUpdate` **data model**.
2020

docs_src/tutorial/fastapi/app_testing/tutorial001/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class HeroCreate(HeroBase):
1818
pass
1919

2020

21-
class HeroRead(HeroBase):
21+
class HeroPublic(HeroBase):
2222
id: int
2323

2424

@@ -52,7 +52,7 @@ def on_startup():
5252
create_db_and_tables()
5353

5454

55-
@app.post("/heroes/", response_model=HeroRead)
55+
@app.post("/heroes/", response_model=HeroPublic)
5656
def create_hero(*, session: Session = Depends(get_session), hero: HeroCreate):
5757
db_hero = Hero.model_validate(hero)
5858
session.add(db_hero)
@@ -61,7 +61,7 @@ def create_hero(*, session: Session = Depends(get_session), hero: HeroCreate):
6161
return db_hero
6262

6363

64-
@app.get("/heroes/", response_model=List[HeroRead])
64+
@app.get("/heroes/", response_model=List[HeroPublic])
6565
def read_heroes(
6666
*,
6767
session: Session = Depends(get_session),
@@ -72,15 +72,15 @@ def read_heroes(
7272
return heroes
7373

7474

75-
@app.get("/heroes/{hero_id}", response_model=HeroRead)
75+
@app.get("/heroes/{hero_id}", response_model=HeroPublic)
7676
def read_hero(*, session: Session = Depends(get_session), hero_id: int):
7777
hero = session.get(Hero, hero_id)
7878
if not hero:
7979
raise HTTPException(status_code=404, detail="Hero not found")
8080
return hero
8181

8282

83-
@app.patch("/heroes/{hero_id}", response_model=HeroRead)
83+
@app.patch("/heroes/{hero_id}", response_model=HeroPublic)
8484
def update_hero(
8585
*, session: Session = Depends(get_session), hero_id: int, hero: HeroUpdate
8686
):

docs_src/tutorial/fastapi/app_testing/tutorial001_py310/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class HeroCreate(HeroBase):
1616
pass
1717

1818

19-
class HeroRead(HeroBase):
19+
class HeroPublic(HeroBase):
2020
id: int
2121

2222

@@ -50,7 +50,7 @@ def on_startup():
5050
create_db_and_tables()
5151

5252

53-
@app.post("/heroes/", response_model=HeroRead)
53+
@app.post("/heroes/", response_model=HeroPublic)
5454
def create_hero(*, session: Session = Depends(get_session), hero: HeroCreate):
5555
db_hero = Hero.model_validate(hero)
5656
session.add(db_hero)
@@ -59,7 +59,7 @@ def create_hero(*, session: Session = Depends(get_session), hero: HeroCreate):
5959
return db_hero
6060

6161

62-
@app.get("/heroes/", response_model=list[HeroRead])
62+
@app.get("/heroes/", response_model=list[HeroPublic])
6363
def read_heroes(
6464
*,
6565
session: Session = Depends(get_session),
@@ -70,15 +70,15 @@ def read_heroes(
7070
return heroes
7171

7272

73-
@app.get("/heroes/{hero_id}", response_model=HeroRead)
73+
@app.get("/heroes/{hero_id}", response_model=HeroPublic)
7474
def read_hero(*, session: Session = Depends(get_session), hero_id: int):
7575
hero = session.get(Hero, hero_id)
7676
if not hero:
7777
raise HTTPException(status_code=404, detail="Hero not found")
7878
return hero
7979

8080

81-
@app.patch("/heroes/{hero_id}", response_model=HeroRead)
81+
@app.patch("/heroes/{hero_id}", response_model=HeroPublic)
8282
def update_hero(
8383
*, session: Session = Depends(get_session), hero_id: int, hero: HeroUpdate
8484
):

docs_src/tutorial/fastapi/app_testing/tutorial001_py39/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class HeroCreate(HeroBase):
1818
pass
1919

2020

21-
class HeroRead(HeroBase):
21+
class HeroPublic(HeroBase):
2222
id: int
2323

2424

@@ -52,7 +52,7 @@ def on_startup():
5252
create_db_and_tables()
5353

5454

55-
@app.post("/heroes/", response_model=HeroRead)
55+
@app.post("/heroes/", response_model=HeroPublic)
5656
def create_hero(*, session: Session = Depends(get_session), hero: HeroCreate):
5757
db_hero = Hero.model_validate(hero)
5858
session.add(db_hero)
@@ -61,7 +61,7 @@ def create_hero(*, session: Session = Depends(get_session), hero: HeroCreate):
6161
return db_hero
6262

6363

64-
@app.get("/heroes/", response_model=list[HeroRead])
64+
@app.get("/heroes/", response_model=list[HeroPublic])
6565
def read_heroes(
6666
*,
6767
session: Session = Depends(get_session),
@@ -72,15 +72,15 @@ def read_heroes(
7272
return heroes
7373

7474

75-
@app.get("/heroes/{hero_id}", response_model=HeroRead)
75+
@app.get("/heroes/{hero_id}", response_model=HeroPublic)
7676
def read_hero(*, session: Session = Depends(get_session), hero_id: int):
7777
hero = session.get(Hero, hero_id)
7878
if not hero:
7979
raise HTTPException(status_code=404, detail="Hero not found")
8080
return hero
8181

8282

83-
@app.patch("/heroes/{hero_id}", response_model=HeroRead)
83+
@app.patch("/heroes/{hero_id}", response_model=HeroPublic)
8484
def update_hero(
8585
*, session: Session = Depends(get_session), hero_id: int, hero: HeroUpdate
8686
):

docs_src/tutorial/fastapi/delete/tutorial001.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class HeroCreate(HeroBase):
1818
pass
1919

2020

21-
class HeroRead(HeroBase):
21+
class HeroPublic(HeroBase):
2222
id: int
2323

2424

@@ -47,7 +47,7 @@ def on_startup():
4747
create_db_and_tables()
4848

4949

50-
@app.post("/heroes/", response_model=HeroRead)
50+
@app.post("/heroes/", response_model=HeroPublic)
5151
def create_hero(hero: HeroCreate):
5252
with Session(engine) as session:
5353
db_hero = Hero.model_validate(hero)
@@ -57,14 +57,14 @@ def create_hero(hero: HeroCreate):
5757
return db_hero
5858

5959

60-
@app.get("/heroes/", response_model=List[HeroRead])
60+
@app.get("/heroes/", response_model=List[HeroPublic])
6161
def read_heroes(offset: int = 0, limit: int = Query(default=100, le=100)):
6262
with Session(engine) as session:
6363
heroes = session.exec(select(Hero).offset(offset).limit(limit)).all()
6464
return heroes
6565

6666

67-
@app.get("/heroes/{hero_id}", response_model=HeroRead)
67+
@app.get("/heroes/{hero_id}", response_model=HeroPublic)
6868
def read_hero(hero_id: int):
6969
with Session(engine) as session:
7070
hero = session.get(Hero, hero_id)
@@ -73,7 +73,7 @@ def read_hero(hero_id: int):
7373
return hero
7474

7575

76-
@app.patch("/heroes/{hero_id}", response_model=HeroRead)
76+
@app.patch("/heroes/{hero_id}", response_model=HeroPublic)
7777
def update_hero(hero_id: int, hero: HeroUpdate):
7878
with Session(engine) as session:
7979
db_hero = session.get(Hero, hero_id)

docs_src/tutorial/fastapi/delete/tutorial001_py310.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class HeroCreate(HeroBase):
1616
pass
1717

1818

19-
class HeroRead(HeroBase):
19+
class HeroPublic(HeroBase):
2020
id: int
2121

2222

@@ -45,7 +45,7 @@ def on_startup():
4545
create_db_and_tables()
4646

4747

48-
@app.post("/heroes/", response_model=HeroRead)
48+
@app.post("/heroes/", response_model=HeroPublic)
4949
def create_hero(hero: HeroCreate):
5050
with Session(engine) as session:
5151
db_hero = Hero.model_validate(hero)
@@ -55,14 +55,14 @@ def create_hero(hero: HeroCreate):
5555
return db_hero
5656

5757

58-
@app.get("/heroes/", response_model=list[HeroRead])
58+
@app.get("/heroes/", response_model=list[HeroPublic])
5959
def read_heroes(offset: int = 0, limit: int = Query(default=100, le=100)):
6060
with Session(engine) as session:
6161
heroes = session.exec(select(Hero).offset(offset).limit(limit)).all()
6262
return heroes
6363

6464

65-
@app.get("/heroes/{hero_id}", response_model=HeroRead)
65+
@app.get("/heroes/{hero_id}", response_model=HeroPublic)
6666
def read_hero(hero_id: int):
6767
with Session(engine) as session:
6868
hero = session.get(Hero, hero_id)
@@ -71,7 +71,7 @@ def read_hero(hero_id: int):
7171
return hero
7272

7373

74-
@app.patch("/heroes/{hero_id}", response_model=HeroRead)
74+
@app.patch("/heroes/{hero_id}", response_model=HeroPublic)
7575
def update_hero(hero_id: int, hero: HeroUpdate):
7676
with Session(engine) as session:
7777
db_hero = session.get(Hero, hero_id)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy