Ticket #14426: remove_mysite_from_import.3.diff
File remove_mysite_from_import.3.diff, 10.5 KB (added by , 14 years ago) |
---|
-
docs/intro/overview.txt
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 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 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 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 -
docs/topics/http/urls.txt
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 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'), … … 564 564 565 565 # inner.py 566 566 urlpatterns = patterns('', 567 (r'^archive/$', ' mysite.views.archive'),568 (r'^about/$', ' mysite.views.about'),567 (r'^archive/$', 'views.archive'), 568 (r'^about/$', 'views.about'), 569 569 ) 570 570 571 571 Set two:: … … 577 577 578 578 # inner.py 579 579 urlpatterns = patterns('', 580 (r'^archive/$', ' mysite.views.archive', {'blogid': 3}),581 (r'^about/$', ' mysite.views.about', {'blogid': 3}),580 (r'^archive/$', 'views.archive', {'blogid': 3}), 581 (r'^about/$', 'views.about', {'blogid': 3}), 582 582 ) 583 583 584 584 Note that extra options will *always* be passed to *every* line in the included … … 596 596 For example, given this URLconf in "string" notation:: 597 597 598 598 urlpatterns = patterns('', 599 (r'^archive/$', ' mysite.views.archive'),600 (r'^about/$', ' mysite.views.about'),601 (r'^contact/$', ' mysite.views.contact'),599 (r'^archive/$', 'views.archive'), 600 (r'^about/$', 'views.about'), 601 (r'^contact/$', 'views.contact'), 602 602 ) 603 603 604 604 You can accomplish the same thing by passing objects rather than strings. Just 605 605 be sure to import the objects:: 606 606 607 from mysite.views import archive, about, contact607 from views import archive, about, contact 608 608 609 609 urlpatterns = patterns('', 610 610 (r'^archive/$', archive), -
docs/topics/http/views.txt
138 138 you want to override the 404 view, you can specify ``handler404`` in your 139 139 URLconf, like so:: 140 140 141 handler404 = ' mysite.views.my_custom_404_view'141 handler404 = 'views.my_custom_404_view' 142 142 143 143 Behind the scenes, Django determines the 404 view by looking for ``handler404``. 144 144 By default, URLconfs contain the following line:: … … 186 186 you want to override the view, you can specify ``handler500`` in your 187 187 URLconf, like so:: 188 188 189 handler500 = ' mysite.views.my_custom_error_view'189 handler500 = 'views.my_custom_error_view' 190 190 191 191 Behind the scenes, Django determines the error view by looking for ``handler500``. 192 192 By default, URLconfs contain the following line:: -
docs/topics/db/models.txt
79 79 80 80 INSTALLED_APPS = ( 81 81 #... 82 'my site.myapp',82 'myapp', 83 83 #... 84 84 ) 85 85 … … 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 ZipCode573 from geography.models import ZipCode 574 574 575 575 class Restaurant(models.Model): 576 576 # ... -
docs/topics/db/queries.txt
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 Blog63 >>> 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 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 Entry101 >>> 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 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 Author111 >>> from blog.models import Author 112 112 >>> joe = Author.objects.create(name="Joe") 113 113 >>> entry.authors.add(joe) 114 114 -
docs/topics/generic-views.txt
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 152 153 153 from django.conf.urls.defaults import * 154 154 from django.views.generic import list_detail 155 from mysite.books.models import Publisher155 from books.models import Publisher 156 156 157 157 publisher_info = { 158 158 "queryset" : Publisher.objects.all(), … … 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 376 377 377 .. parsed-literal:: 378 378 379 from mysite.books.views import books_by_publisher379 from books.views import books_by_publisher 380 380 381 381 urlpatterns = patterns('', 382 382 (r'^publishers/$', list_detail.object_list, publisher_info), … … 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, Publisher390 from books.models import Book, Publisher 391 391 392 392 def books_by_publisher(request, name): 393 393 … … 447 447 448 448 .. parsed-literal:: 449 449 450 from mysite.books.views import author_detail450 from books.views import author_detail 451 451 452 452 urlpatterns = patterns('', 453 453 #... … … 457 457 Then we'd write our wrapper function:: 458 458 459 459 import datetime 460 from mysite.books.models import Author460 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 -
docs/ref/contrib/formtools/form-wizard.txt
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, ContactWizard196 from testapp.forms import ContactForm1, ContactForm2, ContactWizard 197 197 198 198 urlpatterns = patterns('', 199 199 (r'^contact/$', ContactWizard([ContactForm1, ContactForm2])), -
docs/ref/contrib/sitemaps.txt
95 95 your sitemap class might look:: 96 96 97 97 from django.contrib.sitemaps import Sitemap 98 from mysite.blog.models import Entry98 from blog.models import Entry 99 99 100 100 class BlogSitemap(Sitemap): 101 101 changefreq = "never" … … 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 Entry245 from blog.models import Entry 246 246 247 247 info_dict = { 248 248 'queryset': Entry.objects.all(),