Changeset 90
- Timestamp:
- 07/15/05 21:40:24 (3 years ago)
- Files:
-
- django/trunk/docs/overview.txt (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/docs/overview.txt
r69 r90 25 25 meta.CharField('full_name', "reporter's full name", maxlength=70), 26 26 ) 27 27 28 28 def __repr__(self): 29 29 return self.full_name 30 30 31 31 class Article(meta.Model): 32 32 fields = ( … … 36 36 meta.ForeignKey(Reporter), 37 37 ) 38 38 39 39 def __repr__(self): 40 40 return self.headline … … 59 59 # Their names are plural versions of the model class names. 60 60 >>> from django.models.news import reporters, articles 61 61 62 62 # No reporters are in the system yet. 63 63 >>> reporters.get_list() 64 64 [] 65 65 66 66 # Create a new Reporter. 67 67 >>> r = reporters.Reporter(id=None, full_name='John Smith') 68 68 69 69 # Save the object into the database. You have to call save() explicitly. 70 70 >>> r.save() 71 71 72 72 # Now it has an ID. 73 73 >>> r.id 74 74 1 75 75 76 76 # Now the new reporter is in the database. 77 77 >>> reporters.get_list() 78 78 [John Smith] 79 79 80 80 # Fields are represented as attributes on the Python object. 81 81 >>> r.full_name 82 82 'John Smith' 83 83 84 84 # Django provides a rich database lookup API that's entirely driven by keyword arguments. 85 85 >>> reporters.get_object(id__exact=1) … … 92 92 Traceback (most recent call last): 93 93 ... 94 django.models. polls.ReporterDoesNotExist: Reporter does not exist for {'id__exact': 2}95 94 django.models.news.ReporterDoesNotExist: Reporter does not exist for {'id__exact': 2} 95 96 96 # Create an article. 97 97 >>> from datetime import datetime 98 98 >>> a = articles.Article(id=None, pub_date=datetime.now(), headline='Django is cool', article='Yeah.', reporter_id=1) 99 99 >>> a.save() 100 100 101 101 # Now the article is in the database. 102 102 >>> articles.get_list() 103 103 [Django is cool] 104 104 105 105 # Article objects get API access to related Reporter objects. 106 106 >>> r = a.get_reporter() 107 107 >>> r.full_name 108 108 'John Smith' 109 109 110 110 # And vice versa: Reporter objects get API access to Article objects. 111 111 >>> r.get_article_list() 112 112 [Django is cool] 113 113 114 114 # The API follows relationships as far as you need. 115 115 # Find all articles by a reporter whose name starts with "John". 116 116 >>> articles.get_list(reporter__full_name__startswith="John") 117 117 [Django is cool] 118 118 119 119 # Change an object by altering its attributes and calling save(). 120 120 >>> r.full_name = 'Billy Goat' 121 121 >>> r.save() 122 122 123 123 # Delete an object with delete(). 124 124 >>> r.delete() … … 168 168 169 169 from django.conf.urls.defaults import * 170 170 171 171 urlpatterns = patterns('', 172 172 (r'^/articles/(?P\d{4})/$', 'myproject.news.views.articles.year_archive'), … … 206 206 207 207 from django.models.news import articles 208 208 209 209 def article_detail(request, year, month, article_id): 210 210 # Use the Django API to find an object matching the URL criteria. … … 236 236 237 237 {% extends "base" %} 238 238 239 239 {% block title %}{{ article.headline }}{% endblock %} 240 240 241 241 {% block content %} 242 242 <h1>{{ article.headline }}</h1> … … 271 271 Here's what the "base" template might look like:: 272 272 273 273 274 274 <html> 275 275 <head> … … 301 301 302 302 * A caching framework that integrates with memcached or other backends. 303 * An RSS framework that makes creating RSS feeds as easy as writing a 303 * An RSS framework that makes creating RSS feeds as easy as writing a 304 304 small Python class. 305 305 * More sexy automatically-generated admin features -- this overview barely
