Absolute urls in models

, , django, querysets

Everybody knows about permalink, but it's usually used only in get_absolute_url. I prefer to use it for all related model urls.

class Event(models.Model):
    # ...
    @models.permalink
    def edit_url(self):
        return ('event_edit', (self.pk, ))

And then in template:

<a href="{{ event.edit_url }}">Редактировать событие</a>
contact us right now