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 ourterms of serviceand privacy statement.We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📝 Add documentation on how to use the Django ORM inside FastAPI #11782

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

Conversation

patrick91
Copy link

  • Add initial documentation for using the Django ORM
  • Add async example

@tiangolo
Copy link
Member

tiangolo commented Jul 1, 2024

📝 Docs preview for commit1b83a5dat:https://89c6eacf.fastapitiangolo.pages.dev

@alejsdev alejsdev added the docs Documentation about how to use FastAPI label Jul 1, 2024
@tiangolo
Copy link
Member

tiangolo commented Jul 3, 2024

📝 Docs preview for commit85ea9aeat:https://70478e6c.fastapitiangolo.pages.dev

@tiangolo
Copy link
Member

tiangolo commented Jul 3, 2024

📝 Docs preview for commit5909e93at:https://1421e46e.fastapitiangolo.pages.dev

@tiangolo
Copy link
Member

tiangolo commented Jul 3, 2024

📝 Docs preview for commite639870at:https://cbdcbcd0.fastapitiangolo.pages.dev

@tiangolo
Copy link
Member

tiangolo commented Jul 3, 2024

📝 Docs preview for commit048a762at:https://5ee78811.fastapitiangolo.pages.dev

@tiangolo
Copy link
Member

tiangolo commented Jul 3, 2024

📝 Docs preview for commit3768b3cat:https://3f3e5c23.fastapitiangolo.pages.dev

@tiangolo
Copy link
Member

tiangolo commented Jul 3, 2024

📝 Docs preview for commitd259c13at:https://ee45910f.fastapitiangolo.pages.dev

@tiangolo
Copy link
Member

tiangolo commented Jul 3, 2024

📝 Docs preview for commit5e49b3fat:https://1fc2129e.fastapitiangolo.pages.dev

@patrick91 patrick91 marked this pull request as ready for review July 3, 2024 15:36
@patrick91 patrick91 mentioned this pull request Jul 8, 2024
5 tasks
@YuriiMotov
Copy link
Contributor

YuriiMotov commented Jul 11, 2024

I think it would be better to move this guide to "How To - Recipes" section.

Also, using global object to access DB session is not a good practice. It should be at least moved to dependency to allow it to be overridden in tests.

Overall, I like the manner of presentation, and I find this guide useful.

Copy link
Contributor

@svlandeg svlandeg self-assigned this Aug 28, 2024
Copy link
Contributor

Copy link
Contributor

Copy link
Member

@svlandeg svlandeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is a nice addition to the docs 🎉

I've gone ahead and fixed the code examples which are marked up slightly differently since a recent PR tomaster.It looks good on the preview now. Otherwise only a few small comments/suggestions 🙂

Comment on lines +84 to +85
Django's support for async is currently limited, if you need to do run any query in an async route (or function),
you need to either use the async equivalent of the query or use `sync_to_async` from `asgiref.sync` to run the query:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
Django's support for async is currently limited,ifyou need todorun any query in an async route (or function),
you need to either use the async equivalent of the query or use`sync_to_async`from`asgiref.sync`to run the query:
Django's support for async is currently limited.Ifyou need to run any query in an async route (or function),
you need to either use the async equivalent of the query or use`sync_to_async`from`asgiref.sync`to run the query:


HERE = pathlib.Path(__file__).parent

sys.path.append(str(HERE.parents[2] / "docs_src" / "django_orm" ))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'm usually wary of messing withsys.path,is this the only way to make this work?

Comment on lines +89 to +91
```Python
{!>../../../docs_src/django_orm/tutorial001.py[ln:23-37]!}
```
Copy link
Member

@svlandeg svlandeg Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Would it make sense to include the full code fromtutorial001.pysomewhere at the end, to make it even easier on the reader to replicate all this?

@svlandeg svlandeg assignedpatrick91and unassignedsvlandeg Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation about how to use FastAPI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants