RTFMing
Since I've been spending a lot of time learning Flex I haven't been following Django quite so closely. Finding myself with a dead spot yesterday I figured I'd have a look at updates to the model documentation for changes to model inheritance.
A lack of model inheritance (in SVN) is one of the main barriers to our adopting Django for the full gamut of projects; (n)hiberate often makes too compelling a case which is such a same. However, there is promising talk of SQLAlchemy being used as a drop in replacement for Django's native ORM.
Permalink decorator
Browsing the documentation, I discovered the new(ish) permalink decorator which addresses the accidental coupling of model and view (in the MVC sense):
class Widget(models.Model):
...
def get_absolute_url(self):
return "/widget/%i/" % self.id
This binds the absolute url of widget to http://example.com/widget/1/ etc. via the model itself. Yuck.
With the new permalink decorator and given a url conf like:
(r'^/widget/(d+)/$', 'widgets.views.detail'),
The absolute url can be decoupled from the model like this:
from django.db.models import permalink
class Widget(models.Model):
...
def get_absolute_url(self):
return ('widgets.views.detail', [str(self.id)])
get_absolute_url = permalink(get_absolute_url)
It's not perfect because the model is now bound to the view (in the Django sense) which now needs to exist wherever the model exists, however it's vastly superior to permanently binding the model to a particular URI.
Django gets more exciting every day.

Feed
Comments 2
Helloqmi - this is just a testing, dont worry about it
Posted July 2, 2007 at 4:50 a.m. ¶I had enjoyed staying at your site, buy my home page is cooler
Posted July 2, 2007 at 4:50 a.m. ¶Comments are now closed.