Django

Code

Changeset 90

Show
Ignore:
Timestamp:
07/15/05 21:40:24 (3 years ago)
Author:
adrian
Message:

Fixed small typo in overview

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/overview.txt

    r69 r90  
    2525            meta.CharField('full_name', "reporter's full name", maxlength=70), 
    2626        ) 
    27      
     27 
    2828        def __repr__(self): 
    2929            return self.full_name 
    30      
     30 
    3131    class Article(meta.Model): 
    3232        fields = ( 
     
    3636            meta.ForeignKey(Reporter), 
    3737        ) 
    38      
     38 
    3939        def __repr__(self): 
    4040            return self.headline 
     
    5959    # Their names are plural versions of the model class names. 
    6060    >>> from django.models.news import reporters, articles 
    61      
     61 
    6262    # No reporters are in the system yet. 
    6363    >>> reporters.get_list() 
    6464    [] 
    65      
     65 
    6666    # Create a new Reporter. 
    6767    >>> r = reporters.Reporter(id=None, full_name='John Smith') 
    68      
     68 
    6969    # Save the object into the database. You have to call save() explicitly. 
    7070    >>> r.save() 
    71      
     71 
    7272    # Now it has an ID. 
    7373    >>> r.id 
    7474    1 
    75      
     75 
    7676    # Now the new reporter is in the database. 
    7777    >>> reporters.get_list() 
    7878    [John Smith] 
    79      
     79 
    8080    # Fields are represented as attributes on the Python object. 
    8181    >>> r.full_name 
    8282    'John Smith' 
    83      
     83 
    8484    # Django provides a rich database lookup API that's entirely driven by keyword arguments. 
    8585    >>> reporters.get_object(id__exact=1) 
     
    9292    Traceback (most recent call last): 
    9393        ... 
    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 
    9696    # Create an article. 
    9797    >>> from datetime import datetime 
    9898    >>> a = articles.Article(id=None, pub_date=datetime.now(), headline='Django is cool', article='Yeah.', reporter_id=1) 
    9999    >>> a.save() 
    100      
     100 
    101101    # Now the article is in the database. 
    102102    >>> articles.get_list() 
    103103    [Django is cool] 
    104      
     104 
    105105    # Article objects get API access to related Reporter objects. 
    106106    >>> r = a.get_reporter() 
    107107    >>> r.full_name 
    108108    'John Smith' 
    109      
     109 
    110110    # And vice versa: Reporter objects get API access to Article objects. 
    111111    >>> r.get_article_list() 
    112112    [Django is cool] 
    113      
     113 
    114114    # The API follows relationships as far as you need. 
    115115    # Find all articles by a reporter whose name starts with "John". 
    116116    >>> articles.get_list(reporter__full_name__startswith="John") 
    117117    [Django is cool] 
    118      
     118 
    119119    # Change an object by altering its attributes and calling save(). 
    120120    >>> r.full_name = 'Billy Goat' 
    121121    >>> r.save() 
    122      
     122 
    123123    # Delete an object with delete(). 
    124124    >>> r.delete() 
     
    168168 
    169169    from django.conf.urls.defaults import * 
    170      
     170 
    171171    urlpatterns = patterns('', 
    172172        (r'^/articles/(?P\d{4})/$',                   'myproject.news.views.articles.year_archive'), 
     
    206206 
    207207    from django.models.news import articles 
    208      
     208 
    209209    def article_detail(request, year, month, article_id): 
    210210        # Use the Django API to find an object matching the URL criteria. 
     
    236236 
    237237    {% extends "base" %} 
    238      
     238 
    239239    {% block title %}{{ article.headline }}{% endblock %} 
    240      
     240 
    241241    {% block content %} 
    242242    <h1>{{ article.headline }}</h1> 
     
    271271Here's what the "base" template might look like:: 
    272272 
    273      
     273 
    274274    <html> 
    275275    <head> 
     
    301301 
    302302    * 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 
    304304      small Python class. 
    305305    * More sexy automatically-generated admin features -- this overview barely