@@ -33,29 +33,23 @@ and delete functions on your model objects.
3333 From your Python shell, run the following code to import
3434 your models and the module for creating a ``datetime`` object:
3535
36- .. code-block :: python
37-
38- from sample_mflix.models import Movie, Award, Viewer
39- from django.utils import timezone
40- from datetime import datetime
36+ .. literalinclude :: /includes/get-started/read-write-data.py
37+ :start-after: start-imports
38+ :end-before: end-imports
39+ :language: python
40+ :copyable:
4141
4242 .. step:: Insert a movie into the database
4343
4444 Run the following code to create an ``Movie`` object that
4545 stores data about a movie titled ``"Minari"``, including
4646 its awards in an ``Award`` object:
4747
48- .. code-block:: python
49-
50- movie_awards = Award(wins=122, nominations=245, text="Won 1 Oscar")
51- movie = Movie.objects.create(
52- title="Minari",
53- plot="A Korean-American family moves to an Arkansas farm in search of their own American Dream",
54- runtime=217,
55- released=timezone.make_aware(datetime(2020, 1, 26)),
56- awards=movie_awards,
57- genres=["Drama", "Comedy"]
58- )
48+ .. literalinclude:: /includes/get-started/read-write-data.py
49+ :start-after: start-insert-movie
50+ :end-before: end-insert-movie
51+ :language: python
52+ :copyable:
5953
6054 .. step:: Update your movie object
6155
@@ -64,35 +58,35 @@ and delete functions on your model objects.
6458
6559 Run the following code to update the object's ``runtime`` value:
6660
67- .. code-block:: python
68-
69- movie.runtime = 117
70- movie.save()
61+ .. literalinclude:: /includes/get-started/read-write-data.py
62+ :start-after: start-update-movie
63+ :end-before: end-update-movie
64+ :language: python
65+ :copyable:
7166
7267 .. step:: Insert a viewer into the database
7368
7469 You can also use your ``Viewer`` model to insert documents into the
7570 ``sample_mflix.users`` collection. Run the following code to create
7671 a ``Viewer`` object that stores data about a movie viewer named ``"Abigail Carter"``:
7772
78- .. code-block:: python
79-
80- viewer = Viewer.objects.create(
81- name="Abigail Carter",
82- 83- password="secure123"
84- )
73+ .. literalinclude:: /includes/get-started/read-write-data.py
74+ :start-after: start-insert-viewer
75+ :end-before: end-insert-viewer
76+ :language: python
77+ :copyable:
8578
8679 .. step:: Delete a viewer object
8780
8881 One movie viewer named "Alliser Thorne" no longer uses the movie streaming
8982 site. To remove this viewer's corresponding document from the database,
9083 run the following code:
9184
92- .. code-block:: python
93-
94- old_viewer = Viewer.objects.filter(name="Alliser Thorne").first()
95- old_viewer.delete()
85+ .. literalinclude:: /includes/get-started/read-write-data.py
86+ :start-after: start-delete-viewer
87+ :end-before: end-delete-viewer
88+ :language: python
89+ :copyable:
9690
9791 .. step:: Start the development server
9892
0 commit comments