Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #14426 -- Removed "mysite" import statements from examples that…

… might teach people "bad habits" in regards to creating reusable apps.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14270 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7baee5b95384f19b2f579046a344d294eb5f67c6 1 parent 2790cf4
authored October 19, 2010
14  docs/intro/overview.txt
@@ -21,7 +21,8 @@ code.
21 21
 
22 22
 The :doc:`data-model syntax </topics/db/models>` offers many rich ways of
23 23
 representing your models -- so far, it's been solving two years' worth of
24  
-database-schema problems. Here's a quick example::
  24
+database-schema problems. Here's a quick example, which might be saved in
  25
+the file ``mysite/news/models.py``::
25 26
 
26 27
     class Reporter(models.Model):
27 28
         full_name = models.CharField(max_length=70)
@@ -57,7 +58,8 @@ Enjoy the free API
57 58
 With that, you've got a free, and rich, :doc:`Python API </topics/db/queries>` to
58 59
 access your data. The API is created on the fly, no code generation necessary::
59 60
 
60  
-    >>> from mysite.models import Reporter, Article
  61
+    # Import the models we created from our "news" app
  62
+    >>> from news.models import Reporter, Article
61 63
 
62 64
     # No reporters are in the system yet.
63 65
     >>> Reporter.objects.all()
@@ -177,9 +179,9 @@ example above::
177 179
     from django.conf.urls.defaults import *
178 180
 
179 181
     urlpatterns = patterns('',
180  
-        (r'^articles/(\d{4})/$', 'mysite.views.year_archive'),
181  
-        (r'^articles/(\d{4})/(\d{2})/$', 'mysite.views.month_archive'),
182  
-        (r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'mysite.views.article_detail'),
  182
+        (r'^articles/(\d{4})/$', 'news.views.year_archive'),
  183
+        (r'^articles/(\d{4})/(\d{2})/$', 'news.views.month_archive'),
  184
+        (r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'news.views.article_detail'),
183 185
     )
184 186
 
185 187
 The code above maps URLs, as simple regular expressions, to the location of
@@ -195,7 +197,7 @@ is a simple Python function. Each view gets passed a request object --
195 197
 which contains request metadata -- and the values captured in the regex.
196 198
 
197 199
 For example, if a user requested the URL "/articles/2005/05/39323/", Django
198  
-would call the function ``mysite.views.article_detail(request,
  200
+would call the function ``news.views.article_detail(request,
199 201
 '2005', '05', '39323')``.
200 202
 
201 203
 Write your views
2  docs/ref/contrib/formtools/form-wizard.txt
@@ -193,7 +193,7 @@ wizard takes a list of your :class:`~django.forms.Form` objects as
193 193
 arguments when you instantiate the Wizard::
194 194
 
195 195
     from django.conf.urls.defaults import *
196  
-    from mysite.testapp.forms import ContactForm1, ContactForm2, ContactWizard
  196
+    from testapp.forms import ContactForm1, ContactForm2, ContactWizard
197 197
 
198 198
     urlpatterns = patterns('',
199 199
         (r'^contact/$', ContactWizard([ContactForm1, ContactForm2])),
4  docs/ref/contrib/sitemaps.txt
@@ -95,7 +95,7 @@ sitemap to include all the links to your individual blog entries. Here's how
95 95
 your sitemap class might look::
96 96
 
97 97
     from django.contrib.sitemaps import Sitemap
98  
-    from mysite.blog.models import Entry
  98
+    from blog.models import Entry
99 99
 
100 100
     class BlogSitemap(Sitemap):
101 101
         changefreq = "never"
@@ -242,7 +242,7 @@ Here's an example of a :doc:`URLconf </topics/http/urls>` using both::
242 242
 
243 243
     from django.conf.urls.defaults import *
244 244
     from django.contrib.sitemaps import FlatPageSitemap, GenericSitemap
245  
-    from mysite.blog.models import Entry
  245
+    from blog.models import Entry
246 246
 
247 247
     info_dict = {
248 248
         'queryset': Entry.objects.all(),
2  docs/topics/db/models.txt
@@ -570,7 +570,7 @@ It's perfectly OK to relate a model to one from another app. To do this,
570 570
 import the related model at the top of the model that holds your model. Then,
571 571
 just refer to the other model class wherever needed. For example::
572 572
 
573  
-    from mysite.geography.models import ZipCode
  573
+    from geography.models import ZipCode
574 574
 
575 575
     class Restaurant(models.Model):
576 576
         # ...
6  docs/topics/db/queries.txt
@@ -60,7 +60,7 @@ funky model importing.)
60 60
 
61 61
 Assuming models live in a file ``mysite/blog/models.py``, here's an example::
62 62
 
63  
-    >>> from mysite.blog.models import Blog
  63
+    >>> from blog.models import Blog
64 64
     >>> b = Blog(name='Beatles Blog', tagline='All the latest Beatles news.')
65 65
     >>> b.save()
66 66
 
@@ -98,7 +98,7 @@ Updating a ``ForeignKey`` field works exactly the same way as saving a normal
98 98
 field; simply assign an object of the right type to the field in question.
99 99
 This example updates the ``blog`` attribute of an ``Entry`` instance ``entry``::
100 100
 
101  
-    >>> from mysite.blog.models import Entry
  101
+    >>> from blog.models import Entry
102 102
     >>> entry = Entry.objects.get(pk=1)
103 103
     >>> cheese_blog = Blog.objects.get(name="Cheddar Talk")
104 104
     >>> entry.blog = cheese_blog
@@ -108,7 +108,7 @@ Updating a ``ManyToManyField`` works a little differently; use the ``add()``
108 108
 method on the field to add a record to the relation. This example adds the
109 109
 ``Author`` instance ``joe`` to the ``entry`` object::
110 110
 
111  
-    >>> from mysite.blog.models import Author
  111
+    >>> from blog.models import Author
112 112
     >>> joe = Author.objects.create(name="Joe")
113 113
     >>> entry.authors.add(joe)
114 114
 
14  docs/topics/generic-views.txt
@@ -72,7 +72,7 @@ the URLconf to point to a view function:
72 72
 
73 73
     from django.conf.urls.defaults import *
74 74
     from django.views.generic.simple import direct_to_template
75  
-    **from mysite.books.views import about_pages**
  75
+    **from books.views import about_pages**
76 76
 
77 77
     urlpatterns = patterns('',
78 78
         ('^about/$', direct_to_template, {
@@ -152,7 +152,7 @@ To build a list page of all publishers, we'd use a URLconf along these lines::
152 152
 
153 153
     from django.conf.urls.defaults import *
154 154
     from django.views.generic import list_detail
155  
-    from mysite.books.models import Publisher
  155
+    from books.models import Publisher
156 156
 
157 157
     publisher_info = {
158 158
         "queryset" : Publisher.objects.all(),
@@ -251,7 +251,7 @@ detail view, we'd use an info dict like this:
251 251
 
252 252
 .. parsed-literal::
253 253
 
254  
-    from mysite.books.models import Publisher, **Book**
  254
+    from books.models import Publisher, **Book**
255 255
 
256 256
     publisher_info = {
257 257
         "queryset" : Publisher.objects.all(),
@@ -376,7 +376,7 @@ of code by hand. As usual, we'll start by writing a URLconf:
376 376
 
377 377
 .. parsed-literal::
378 378
 
379  
-    from mysite.books.views import books_by_publisher
  379
+    from books.views import books_by_publisher
380 380
 
381 381
     urlpatterns = patterns('',
382 382
         (r'^publishers/$', list_detail.object_list, publisher_info),
@@ -387,7 +387,7 @@ Next, we'll write the ``books_by_publisher`` view itself::
387 387
 
388 388
     from django.http import Http404
389 389
     from django.views.generic import list_detail
390  
-    from mysite.books.models import Book, Publisher
  390
+    from books.models import Book, Publisher
391 391
 
392 392
     def books_by_publisher(request, name):
393 393
 
@@ -447,7 +447,7 @@ custom view:
447 447
 
448 448
 .. parsed-literal::
449 449
 
450  
-    from mysite.books.views import author_detail
  450
+    from books.views import author_detail
451 451
 
452 452
     urlpatterns = patterns('',
453 453
         #...
@@ -457,7 +457,7 @@ custom view:
457 457
 Then we'd write our wrapper function::
458 458
 
459 459
     import datetime
460  
-    from mysite.books.models import Author
  460
+    from books.models import Author
461 461
     from django.views.generic import list_detail
462 462
     from django.shortcuts import get_object_or_404
463 463
 
10  docs/topics/http/urls.txt
@@ -338,12 +338,12 @@ Here's the example URLconf from the :doc:`Django overview </intro/overview>`::
338 338
     from django.conf.urls.defaults import *
339 339
 
340 340
     urlpatterns = patterns('',
341  
-        (r'^articles/(\d{4})/$', 'mysite.news.views.year_archive'),
342  
-        (r'^articles/(\d{4})/(\d{2})/$', 'mysite.news.views.month_archive'),
343  
-        (r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'mysite.news.views.article_detail'),
  341
+        (r'^articles/(\d{4})/$', 'news.views.year_archive'),
  342
+        (r'^articles/(\d{4})/(\d{2})/$', 'news.views.month_archive'),
  343
+        (r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'news.views.article_detail'),
344 344
     )
345 345
 
346  
-In this example, each view has a common prefix -- ``'mysite.news.views'``.
  346
+In this example, each view has a common prefix -- ``'news.views'``.
347 347
 Instead of typing that out for each entry in ``urlpatterns``, you can use the
348 348
 first argument to the ``patterns()`` function to specify a prefix to apply to
349 349
 each view function.
@@ -352,7 +352,7 @@ With this in mind, the above example can be written more concisely as::
352 352
 
353 353
     from django.conf.urls.defaults import *
354 354
 
355  
-    urlpatterns = patterns('mysite.news.views',
  355
+    urlpatterns = patterns('news.views',
356 356
         (r'^articles/(\d{4})/$', 'year_archive'),
357 357
         (r'^articles/(\d{4})/(\d{2})/$', 'month_archive'),
358 358
         (r'^articles/(\d{4})/(\d{2})/(\d+)/$', 'article_detail'),

0 notes on commit 7baee5b

Please sign in to comment.
Something went wrong with that request. Please try again.