@@ -43,45 +43,9 @@ To learn more about the ``sample_mflix`` database, see :atlas:`Sample Mflix Data
43
43
Open the ``models.py`` file in the ``sample_mflix`` directory and replace
44
44
its contents with the following code:
45
45
46
- .. code-block:: python
47
-
48
- from django.db import models
49
- from django_mongodb_backend.fields import EmbeddedModelField, ArrayField
50
-
51
- class Award(models.Model):
52
- wins = models.IntegerField(default=0)
53
- nominations = models.IntegerField(default=0)
54
- text = models.CharField(max_length=100)
55
-
56
- class Meta:
57
- managed = False
58
-
59
- class Movie(models.Model):
60
- title = models.CharField(max_length=200)
61
- plot = models.TextField(blank=True)
62
- runtime = models.IntegerField(default=0)
63
- released = models.DateTimeField("release date", null=True, blank=True)
64
- awards = EmbeddedModelField(Award, null=True, blank=True)
65
- genres = ArrayField(models.CharField(max_length=100), null=True, blank=True)
66
-
67
- class Meta:
68
- db_table = "movies"
69
- managed = False
70
-
71
- def __str__(self):
72
- return self.title
73
-
74
- class Viewer(models.Model):
75
- name = models.CharField(max_length=100)
76
- email = models.CharField(max_length=200)
77
- password = models.CharField(max_length=100)
78
-
79
- class Meta:
80
- db_table = "users"
81
- managed = False
82
-
83
- def __str__(self):
84
- return self.name
46
+ .. literalinclude:: /includes/get-started/models.py
47
+ :language: python
48
+ :copyable:
85
49
86
50
The ``Movie`` model represents the ``sample_mflix.movies`` collection
87
51
and stores information about movies. This model contains an embedded
@@ -100,23 +64,9 @@ To learn more about the ``sample_mflix`` database, see :atlas:`Sample Mflix Data
100
64
Open the ``views.py`` file in your ``sample_mflix`` directory and replace
101
65
its contents with the following code:
102
66
103
- .. code-block:: python
104
-
105
- from django.http import HttpResponse
106
- from django.shortcuts import render
107
-
108
- from .models import Movie, Viewer
109
-
110
- def index(request):
111
- return HttpResponse("Hello, world. You're at the application index.")
112
-
113
- def recent_movies(request):
114
- movies = Movie.objects.order_by("-released")[:5]
115
- return render(request, "recent_movies.html", {"movies": movies})
116
-
117
- def viewers_list(request):
118
- viewers = Viewer.objects.order_by("name")[:10]
119
- return render(request, "viewers_list.html", {"viewers": viewers})
67
+ .. literalinclude:: /includes/get-started/views.py
68
+ :language: python
69
+ :copyable:
120
70
121
71
These views display a landing page message and information about your ``Movie``
122
72
and ``Viewer`` models.
@@ -127,18 +77,10 @@ To learn more about the ``sample_mflix`` database, see :atlas:`Sample Mflix Data
127
77
To map the views defined in the preceding step to URLs, paste the following
128
78
code into ``urls.py``:
129
79
130
- .. code-block:: python
80
+ .. literalinclude:: /includes/get-started/urls.py
81
+ :language: python
82
+ :copyable:
131
83
132
- from django.urls import path
133
-
134
- from . import views
135
-
136
- urlpatterns = [
137
- path("", views.index, name="index"),
138
- path("recent_movies/", views.recent_movies, name="recent_movies"),
139
- path("viewers_list/", views.viewers_list, name="viewers_list"),
140
- ]
141
-
142
84
Then, navigate to the ``quickstart/urls.py`` file and replace its contents with
143
85
the following code:
144
86
@@ -158,69 +100,18 @@ To learn more about the ``sample_mflix`` database, see :atlas:`Sample Mflix Data
158
100
``templates``. Then, create a file called ``recent_movies.html``
159
101
and paste the following code:
160
102
161
- .. code-block:: html
162
-
163
- <!-- templates/recent_movies.html -->
164
- <!DOCTYPE html>
165
- <html lang="en">
166
- <head>
167
- <meta charset="UTF-8">
168
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
169
- <title>Recent Movies</title>
170
- </head>
171
- <body>
172
- <h1>Five Most Recent Movies</h1>
173
- <ul>
174
- {% for movie in movies %}
175
- <li>
176
- <strong>{{ movie.title }}</strong> (Released: {{ movie.released }})
177
- </li>
178
- {% empty %}
179
- <li>No movies found.</li>
180
- {% endfor %}
181
- </ul>
182
- </body>
183
- </html>
103
+ .. literalinclude:: /includes/get-started/recent_movies.html
104
+ :language: html
105
+ :copyable:
184
106
185
107
This template formats the movie data requested by the ``recent_movies`` view.
186
108
187
109
Create another file in the ``sample_mflix/templates`` directory called
188
110
``viewers_list.html`` and paste the following code:
189
111
190
- .. code-block:: html
191
-
192
- <!-- templates/viewers_list.html -->
193
- <!DOCTYPE html>
194
- <html lang="en">
195
- <head>
196
- <meta charset="UTF-8">
197
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
198
- <title>Viewers List</title>
199
- </head>
200
- <body>
201
- <h1>Alphabetical Viewers List</h1>
202
- <table>
203
- <thead>
204
- <tr>
205
- <th>Name</th>
206
- <th>Email</th>
207
- </tr>
208
- </thead>
209
- <tbody>
210
- {% for viewer in viewers %}
211
- <tr>
212
- <td>{{ viewer.name }}</td>
213
- <td>{{ viewer.email }}</td>
214
- </tr>
215
- {% empty %}
216
- <tr>
217
- <td colspan="2">No viewer found.</td>
218
- </tr>
219
- {% endfor %}
220
- </tbody>
221
- </table>
222
- </body>
223
- </html>
112
+ .. literalinclude:: /includes/get-started/viewers_list.html
113
+ :language: html
114
+ :copyable:
224
115
225
116
This template formats the user data requested by the ``viewers_list`` view.
226
117
0 commit comments