Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

**@models.permalink
AttributeError: module 'django.db.models' has no attribute 'permalink'**
like image 588
Monadroid Avatar asked Oct 27 '25 05:10

Monadroid


1 Answers

As of django-1.11, the @permalink decorator was marked deprecated [Django-doc], and since django-2.1, 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'))
like image 118
Willem Van Onsem Avatar answered Oct 28 '25 17:10

Willem Van Onsem



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!