I am getting this error. How can I solve it?
**@models.permalink
AttributeError: module 'django.db.models' has no attribute 'permalink'**
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'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With