Django

Code

Changeset 4891

Show
Ignore:
Timestamp:
04/01/07 00:22:14 (2 years ago)
Author:
adrian
Message:

Edited docs/model-api.txt permalink changes from [4879]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/model-api.txt

    r4879 r4891  
    13081308      can't be used in sorting (because Django does all the sorting at the 
    13091309      database level). 
    1310        
     1310 
    13111311      However, if an element of ``list_display`` represents a certain database 
    13121312      field, you can indicate this fact by setting the ``admin_order_field`` 
    13131313      attribute of the item. 
    1314        
     1314 
    13151315      For example:: 
    1316        
     1316 
    13171317        class Person(models.Model): 
    13181318            first_name = models.CharField(maxlength=50) 
     
    13261326            colored_first_name.allow_tags = True 
    13271327            colored_first_name.admin_order_field = 'first_name' 
    1328      
     1328 
    13291329      The above will tell Django to order by the ``first_name`` field when 
    13301330      trying to sort by ``colored_first_name`` in the admin. 
     
    17601760You can further decouple your models from the URLconf using the ``permalink`` 
    17611761decorator. This decorator is passed the view function, a list of positional 
    1762 parameters and (optionally) a dictionary of named parameters. Django then 
     1762parameters and (optionally) a dictionary of named parameters. Django then 
    17631763works out the correct full URL path using the URLconf, substituting the 
    17641764parameters you have given into the URL. For example, if your URLconf 
     
    17751775    get_absolute_url = permalink(get_absolute_url) 
    17761776 
    1777  
    1778 Similraly, if you had a URLconf entry that looked like:: 
    1779  
    1780     (r'/archive/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$', 
    1781         archive_view) 
     1777Similarly, if you had a URLconf entry that looked like:: 
     1778 
     1779    (r'/archive/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$', archive_view) 
    17821780 
    17831781...you could reference this using ``permalink()`` as follows:: 
     
    17911789 
    17921790Notice that we specify an empty sequence for the second argument in this case, 
    1793 since we're only wanting to pass in some keyword arguments. 
     1791because we only want to pass keyword arguments, not named arguments. 
    17941792 
    17951793In this way, you're tying the model's absolute URL to the view that is used