Author: mtredinnick
Date: 2007-02-16 23:51:45 -0600 (Fri, 16 Feb 2007)
New Revision: 4535
Modified:
django/trunk/docs/model-api.txt
Log:
Fixed #2568 -- Added documentation for the permalink() decorator. Based on a
patch from Joeboy.
Modified: django/trunk/docs/model-api.txt
===================================================================
--- django/trunk/docs/model-api.txt 2007-02-17 04:59:49 UTC (rev 4534)
+++ django/trunk/docs/model-api.txt 2007-02-17 05:51:45 UTC (rev 4535)
@@ -1721,12 +1721,31 @@
<a href="{{ object.get_absolute_url }}">{{ object.name }}</a>
-(Yes, we know ``get_absolute_url()`` couples URLs to models, which violates the
-DRY principle, because URLs are defined both in a URLconf and in the model.
-This is a rare case in which we've intentionally violated that principle for
-the sake of convenience. With that said, we're working on an even cleaner way
-of specifying URLs in a more DRY fashion.)
+``permalink``
+-------------
+** New in Django development version. **
+
+The problem with the way we wrote ``get_absolute_url()`` above is that it
+slightly violates the DRY principle: the URL for this object is defined both
+in the URLConf file and in the model.
+
+You can further decouple your models from the URL configuration using the
+``permalink`` function. This function acts as a decorator and is passed the
+view function and any parameters you would use for accessing this instance
+directly. Django then works out the correct full URL path using the URL
+configuration file. For example::
+
+ from django.db.models import permalink
+
+ def get_absolute_url(self):
+ return ('people.views.details', str(self.id))
+ get_absolute_url = permalink(get_absolute_url)
+
+In this way, you are tying the model's absolute URL to the view that is used
+to display it, without repeating the URL information anywhere. You still use
+the ``get_absolute_url`` method in templates, as before.
+
Executing custom SQL
--------------------
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---