Django

Code

Changeset 2765

Show
Ignore:
Timestamp:
04/28/06 00:00:42 (2 years ago)
Author:
adrian
Message:

magic-removal: Quickly proofread docs/forms.txt

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/magic-removal/docs/forms.txt

    r2721 r2765  
    1010 
    1111        If all you want to do is present forms for a user to create and/or 
    12         update a given object, don't read any further. Instead, click thyself 
    13         to the `generic views`_ documentation. The following exercises are 
    14         for those interested in how Django's form framework works and those 
    15         needing to do more than simple creation/updating. 
     12        update a given object, you may be able to use `generic views`_. 
    1613 
    1714We'll take a top-down approach to examining Django's form validation framework, 
     
    3330        zip_code = meta.CharField(maxlength=5, blank=True) 
    3431        place_type = meta.IntegerField(choices=PLACE_TYPES) 
    35         class Meta: 
    36             admin = meta.Admin() 
    37  
    38         def __repr__(self): 
     32 
     33        class Admin: 
     34            pass 
     35 
     36        def __str__(self): 
    3937            return self.name 
    4038 
    41 Defining the above class is enough to create an admin interface to a ``place``, 
     39Defining the above class is enough to create an admin interface to a ``Place``, 
    4240but what if you want to allow public users to submit places? 
    4341 
     
    5452created when you define a new class:: 
    5553 
    56     >>> from django.models.places import places 
    57     >>> places.AddManipulator 
    58     <class django.models.places.PlaceManipulatorAdd at 0x4c1540> 
    59     >>> places.ChangeManipulator 
    60     <class django.models.places.PlaceManipulatorChange at 0x4c1630> 
     54    >>> from mysite.myapp.models import Place 
     55    >>> Place.AddManipulator 
     56    <class Place.ManipulatorAdd at 0x4c1540> 
     57    >>> Place.ChangeManipulator 
     58    <class Place.ManipulatorChange at 0x4c1630> 
    6159 
    6260Using the ``AddManipulator`` 
     
    6866    from django.shortcuts import render_to_response 
    6967    from django.http import Http404, HttpResponse, HttpResponseRedirect 
    70     from django.models.places import places 
     68    from mysite.myapp.models import Place 
    7169    from django import forms 
    7270 
     
    7472        """A naive approach to creating places; don't actually use this!""" 
    7573        # Create the AddManipulator. 
    76         manipulator = places.AddManipulator() 
     74        manipulator = Place.AddManipulator() 
    7775 
    7876        # Make a copy of the POSTed data so that do_html2python can 
     
    110108        # Create a FormWrapper object that the template can use. Ignore 
    111109        # the last two arguments to FormWrapper for now. 
    112         form = forms.FormWrapper(places.AddManipulator(), {}, {}) 
     110        form = forms.FormWrapper(Place.AddManipulator(), {}, {}) 
    113111        return render_to_response('places/naive_create_form.html', {'form': form}) 
    114112 
     
    117115 
    118116The ``forms.FormWrapper`` object is a wrapper that templates can 
    119 easily deal with to create forms. Here's the ``naive_create_form`` template:: 
    120  
    121     {% extends "base" %} 
     117easily deal with to create forms. Here's the ``naive_create_form.html`` 
     118template:: 
     119 
     120    {% extends "base.html" %} 
    122121 
    123122    {% block content %} 
     
    156155 
    157156    def create_place_with_validation(request): 
    158         manipulator = places.AddManipulator() 
     157        manipulator = Place.AddManipulator() 
    159158        new_data = request.POST.copy() 
    160159 
     
    172171on an error page (templated, of course):: 
    173172 
    174     {% extends "base" %} 
     173    {% extends "base.html" %} 
    175174 
    176175    {% block content %} 
     
    209208 
    210209    def create_place(request): 
    211         manipulator = places.AddManipulator() 
     210        manipulator = Place.AddManipulator() 
    212211 
    213212        if request.POST: 
     
    238237and here's the ``create_form`` template:: 
    239238 
    240     {% extends "base" %} 
     239    {% extends "base.html" %} 
    241240 
    242241    {% block content %} 
     
    301300        # ChangeManipulator at the same time. 
    302301        try: 
    303             manipulator = places.ChangeManipulator(place_id) 
    304         except places.PlaceDoesNotExist: 
     302            manipulator = Place.ChangeManipulator(place_id) 
     303        except Place.DoesNotExist: 
    305304            raise Http404 
    306305