mirror of
https://github.com/django/django.git
synced 2025-08-03 02:23:12 +00:00
Refs #18974 -- Deprecated @models.permalink() decorator.
This commit is contained in:
parent
aa9569fce1
commit
0083a4c8e9
4 changed files with 55 additions and 14 deletions
|
@ -1,4 +1,7 @@
|
|||
import warnings
|
||||
|
||||
from django.db import models
|
||||
from django.utils.deprecation import RemovedInDjango21Warning
|
||||
|
||||
|
||||
def set_attr(name, value):
|
||||
|
@ -8,17 +11,20 @@ def set_attr(name, value):
|
|||
return wrapper
|
||||
|
||||
|
||||
class Guitarist(models.Model):
|
||||
name = models.CharField(max_length=50)
|
||||
slug = models.CharField(max_length=50)
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter('ignore', category=RemovedInDjango21Warning)
|
||||
|
||||
@models.permalink
|
||||
def url(self):
|
||||
"Returns the URL for this guitarist."
|
||||
return ('guitarist_detail', [self.slug])
|
||||
class Guitarist(models.Model):
|
||||
name = models.CharField(max_length=50)
|
||||
slug = models.CharField(max_length=50)
|
||||
|
||||
@models.permalink
|
||||
@set_attr('attribute', 'value')
|
||||
def url_with_attribute(self):
|
||||
"Returns the URL for this guitarist and holds an attribute"
|
||||
return ('guitarist_detail', [self.slug])
|
||||
@models.permalink
|
||||
def url(self):
|
||||
"Returns the URL for this guitarist."
|
||||
return ('guitarist_detail', [self.slug])
|
||||
|
||||
@models.permalink
|
||||
@set_attr('attribute', 'value')
|
||||
def url_with_attribute(self):
|
||||
"Returns the URL for this guitarist and holds an attribute"
|
||||
return ('guitarist_detail', [self.slug])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue