Django

Code

Changeset 8966

Show
Ignore:
Timestamp:
09/04/08 19:48:34 (3 months ago)
Author:
adrian
Message:

Made a bunch of edits and typo corrections to 1.0-porting-guide.txt

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/releases/1.0-porting-guide.txt

    r8937 r8966  
    55.. highlight:: python 
    66 
    7 Django 1.0 breaks compatibility with 0.96 in some areas.  
     7Django 1.0 breaks compatibility with 0.96 in some areas. 
    88 
    99This guide will help you port 0.96 projects and apps to 1.0. The first part of 
     
    9898    from django.contrib import admin 
    9999    from models import Author 
    100      
     100 
    101101    class AuthorAdmin(admin.ModelAdmin): 
    102102        list_display = ['first_name', 'last_name'] 
     
    140140    class Parent(models.Model): 
    141141        ... 
    142          
     142 
    143143    class Child(models.Model): 
    144144        parent = models.ForeignKey(Parent, edit_inline=models.STACKED, num_in_admin=3) 
     
    150150        model = Child 
    151151        extra = 3 
    152          
     152 
    153153    class ParentAdmin(models.ModelAdmin): 
    154154        model = Parent 
    155155        inlines = [ChildInline] 
    156          
     156 
    157157    admin.site.register(Parent, ParentAdmin) 
    158      
     158 
    159159See :ref:`admin-inlines` for more details. 
    160160 
     
    165165syntax still works, but you'll need to use ``fieldsets`` instead. 
    166166 
    167 Old (0.96)::     
     167Old (0.96):: 
    168168 
    169169    class ModelOne(models.Model): 
    170170        ... 
    171          
     171 
    172172        class Admin: 
    173173            fields = ( 
    174174                (None, {'fields': ('foo','bar')}), 
    175175            ) 
    176      
     176 
    177177    class ModelTwo(models.Model): 
    178178        ... 
    179          
     179 
    180180        class Admin: 
    181181            fields = ( 
     
    183183                ('group2', {'fields': ('spam','eggs'), 'classes': 'collapse wide'}), 
    184184            ) 
    185              
     185 
    186186 
    187187New (1.0):: 
     
    189189    class ModelOneAdmin(admin.ModelAdmin): 
    190190        fields = ('foo', 'bar') 
    191          
     191 
    192192    class ModelTwoAdmin(admin.ModelAdmin): 
    193193        fieldsets = ( 
     
    195195            ('group2', {'fields': ('spam','eggs'), 'classes': 'collapse wide'}), 
    196196        ) 
    197          
     197 
    198198 
    199199.. seealso:: 
     
    213213~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    214214 
    215 If you are using the admin site you need to update your root ``urls.py``. 
     215If you're using the admin site, you need to update your root ``urls.py``. 
    216216 
    217217Old (0.96) ``urls.py``:: 
     
    247247Replace ``django.newforms`` with ``django.forms`` -- Django 1.0 renamed the 
    248248``newforms`` module (introduced in 0.96) to plain old ``forms``. The 
    249 ``oldforms`` module was also removed removed. 
    250  
    251 If you are already using new forms all you have to do is change your import 
    252 statement. Instead of ``from django import newforms as forms``, use ``from 
    253 django import forms``. 
    254  
    255 If you are using the old forms system, you will have to rewrite your forms. A 
    256 good place to start is the :ref:`forms documentation <topics-forms-index>` 
     249``oldforms`` module was also removed. 
     250 
     251If you're already using the ``newforms`` library, and you used our recommended 
     252``import`` statement syntax, all you have to do is change your import 
     253statements. 
     254 
     255Old:: 
     256 
     257    from django import newforms as forms 
     258 
     259New:: 
     260 
     261    from django import forms 
     262 
     263If you're using the old forms system (formerly known as ``django.forms`` and 
     264``django.oldforms``), you'll have to rewrite your forms. A good place to start 
     265is the :ref:`forms documentation <topics-forms-index>` 
    257266 
    258267Handle uploaded files using the new API 
     
    269278          ... 
    270279 
    271 You'd need to make the following changes: 
     280...you'd need to make the following changes: 
    272281 
    273282===================== ===================== 
     
    285294~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    286295 
    287 By default, the templating system now automatically HTML-escapes the output of 
     296By default, the template system now automatically HTML-escapes the output of 
    288297every variable. To learn more, see :ref:`automatic-html-escaping`. 
    289298 
     
    353362~~~~~~~~~~~~~~~~~~~~~ 
    354363 
    355 The spaceless template tag removes *all* spaces between HTML tags instead of 
    356 preserving a single space. 
    357  
    358 Localflavor 
    359 ----------- 
    360  
    361 US localflavor 
    362 ~~~~~~~~~~~~~~ 
    363  
    364 ``django.contrib.localflavor.usa`` has been renamed 
    365 :mod:`django.contribg.localflavor.us`. This change was made to match the naming 
    366 scheme of other local flavors. 
     364The spaceless template tag now removes *all* spaces between HTML tags, instead 
     365of preserving a single space. 
     366 
     367Local flavors 
     368------------- 
     369 
     370U.S. local flavor 
     371~~~~~~~~~~~~~~~~~ 
     372 
     373``django.contrib.localflavor.usa`` has been renamed to 
     374:mod:`django.contrib.localflavor.us`. This change was made to match the naming 
     375scheme of other local flavors. To migrate your code, all you need to do is 
     376change the imports. 
    367377 
    368378Sessions 
     
    373383 
    374384``SeesionBase.get_new_session_key()`` has been renamed to 
    375 ``_get_new_session_key()``; ``get_new_session_object()`` no longer exists. 
     385``_get_new_session_key()``. ``get_new_session_object()`` no longer exists. 
    376386 
    377387Fixtures 
     
    391401~~~~~~~~~~~~~~~~~ 
    392402 
    393 The old :exc:`EnvironmentError` was split into an :exc:`ImportError` raised when 
     403The old :exc:`EnvironmentError` has split into an :exc:`ImportError` when 
    394404Django fails to find the settings module and a :exc:`RuntimeError` when you try 
    395405to reconfigure settings after having already used them 
     
    402412LOGIN_URL`` refer to :setting:`settings.LOGIN_URL <LOGIN_URL>`. 
    403413 
    404 :setting:`APPEND_SLASH` behaviour has been updated 
    405 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     414:setting:`APPEND_SLASH` behavior has been updated 
     415~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    406416 
    407417In 0.96, if a URL didn't end in a slash or have a period in the final 
    408 component of it's path, and ``APPEND_SLASH`` was True, Django would redirect 
     418component of its path, and ``APPEND_SLASH`` was True, Django would redirect 
    409419to the same URL, but with a slash appended to the end. Now, Django checks to 
    410 see if the pattern without the trailing slash would be matched by something in 
    411 your URL patterns. If so, no redirection takes place, because it is assumed 
    412 you deliberately wanted to catch that pattern. 
     420see whether the pattern without the trailing slash would be matched by 
     421something in your URL patterns. If so, no redirection takes place, because it 
     422is assumed you deliberately wanted to catch that pattern. 
    413423 
    414424For most people, this won't require any changes. Some people, though, have URL 
     
    422432    r'/some_prefix/(.*/)$' 
    423433 
    424 Samller model changes 
     434Smaller model changes 
    425435--------------------- 
    426436 
     
    428438~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    429439 
    430 The models manager now returns a :exc:`MultipleObjectsReturned` exception 
     440Managers now return a :exc:`MultipleObjectsReturned` exception 
    431441instead of :exc:`AssertionError`: 
    432442 
     
    444454  except Model.MultipleObjectsReturned: 
    445455      handle_the_error() 
    446        
     456 
    447457``LazyDate`` has been fired 
    448458~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     
    483493 
    484494If you forget to make this change, you will see errors about ``FloatField`` 
    485 not taking a ``max_digits`` attribute in ``__init__``, since the new 
     495not taking a ``max_digits`` attribute in ``__init__``, because the new 
    486496``FloatField`` takes no precision-related arguments. 
    487497 
    488 If you are using MySQL or PostgreSQL, there are no further changes needed. The 
     498If you're using MySQL or PostgreSQL, no further changes are needed. The 
    489499database column types for ``DecimalField`` are the same as for the old 
    490500``FloatField``. 
    491501 
    492 If you are using SQLite, you need to force the database to view the 
     502If you're using SQLite, you need to force the database to view the 
    493503appropriate columns as decimal types, rather than floats. To do this, you'll 
    494504need to reload your data. Do this after you have made the change to using 
     
    497507.. warning:: 
    498508 
    499   **Back up your database first!**  
    500    
     509  **Back up your database first!** 
     510 
    501511  For SQLite, this means making a copy of the single file that stores the 
    502512  database (the name of that file is the ``DATABASE_NAME`` in your settings.py 
    503513  file). 
    504514 
    505 To upgrade each application to use a ``DecimalField``, do the following, 
    506 replacing ``<app>`` in the code below with each app's name: 
     515To upgrade each application to use a ``DecimalField``, you can do the 
     516following, replacing ``<app>`` in the code below with each app's name: 
    507517 
    508518.. code-block:: bash 
     
    514524Notes: 
    515525 
    516   1. It is important that you remember to use XML format in the first step of 
     526  1. It's important that you remember to use XML format in the first step of 
    517527     this process. We are exploiting a feature of the XML data dumps that makes 
    518528     porting floats to decimals with SQLite possible. 
    519    
     529 
    520530  2. In the second step you will be asked to confirm that you are prepared to 
    521531     lose the data for the application(s) in question. Say yes; we'll restore 
    522532     this data in the third step, of course. 
    523    
    524   3. ``DecimalField`` is not used in any of the apps shipped with Django prior  
     533 
     534  3. ``DecimalField`` is not used in any of the apps shipped with Django prior 
    525535     to this change being made, so you do not need to worry about performing 
    526536     this procedure for any of the standard Django models. 
     
    545555~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    546556 
    547 ``_()`` is no longer monkeypatched into builtins. If you were previously 
    548 relying on ``_()`` always being present, you should now explicitly import 
    549 ``ugettext`` or ``ugettext_lazy``, if appropriate, and alias it to ``_`` 
    550 yourself:: 
     557``_()`` (the callable object whose name is a single underscore) is no longer 
     558monkeypatched into builtins -- that is, it's no longer available magically in 
     559every module. 
     560 
     561If you were previously relying on ``_()`` always being present, you should now 
     562explicitly import ``ugettext`` or ``ugettext_lazy``, if appropriate, and alias 
     563it to ``_`` yourself:: 
    551564 
    552565    from django.utils.translation import ugettext as _ 
     
    594607~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    595608 
    596 :mod:`django.core.management`` has been greately refactored. 
    597  
    598 Calls to management services in your code will now need to use 
     609:mod:`django.core.management`` has been greatly refactored. 
     610 
     611Calls to management services in your code now need to use 
    599612``call_command``. For example, if you have some test code that calls flush and 
    600613load_data:: 
     
    604617      management.load_data(['test_data'], verbosity=0) 
    605618 
    606 You will need to change this code to read:: 
     619...you'll need to change this code to read:: 
    607620 
    608621      from django.core import management 
     
    620633      $ django-admin.py --settings=foo.bar runserver 
    621634 
    622 no longer works, and must be changed to: 
     635...no longer works and should be changed to: 
    623636 
    624637.. code-block:: bash 
     
    632645~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    633646 
    634 The ``__init__()`` parameters in in syndication framework's ``Feed`` class now 
     647The ``__init__()`` parameters in the syndication framework's ``Feed`` class now 
    635648take an ``HttpRequest`` object as its second parameter, instead of the feed's 
    636649URL. This allows the syndication framework to work without requiring the sites 
     
    653666        using ``django.newforms.forms.SortedDictFromList``. 
    654667 
    655      2. Since :meth:`django.utils.datastructures.SortedDict.copy` return
     668     2. Because :meth:`django.utils.datastructures.SortedDict.copy` returns
    656669        deepcopy as ``SortedDictFromList`` method did, you will need to update 
    657670        your code if you were relying on a deepcopy. Do this by using