AttributeError: module 'django.db.models' has no attribute 'permalink'

Viewed 1187

I am getting this error. How can I solve it?

**@models.permalink
AttributeError: module 'django.db.models' has no attribute 'permalink'**
1 Answers

As of , the @permalink decorator was marked deprecated [Django-doc], and since , the @permalink decorator is removed [Django-doc]. There has been some discussion regarding this decorator, and eventually the Django developers decided to remove it.

Instead of using the @permalink decorator for the .get_absolute_url() method [Django-doc], one is now responsible to return the correct values.

This thus means that if you have a model that uses the decorator, you change this from:

class MyModel(models.Model):
    # …

    @models.permalink
    def get_absolute_url(self):
        return ('name-of-some-view', 'extra', 'parameters')

you have to use the reverse(…) function [Django-doc]:

from django.urls import reverse

class MyModel(models.Model):
    # …

    def get_absolute_url(self):
        return reverse('name-of-some-view', args=('extra', 'parameters'))
Related