File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
tests/regressiontests/model_permalink Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 11from django .db import models
22
33
4+ def set_attr (name , value ):
5+ def wrapper (function ):
6+ setattr (function , name , value )
7+ return function
8+ return wrapper
9+
10+
411class Guitarist (models .Model ):
512 name = models .CharField (max_length = 50 )
613 slug = models .CharField (max_length = 50 )
@@ -9,3 +16,9 @@ class Guitarist(models.Model):
916 def url (self ):
1017 "Returns the URL for this guitarist."
1118 return ('guitarist_detail' , [self .slug ])
19+
20+ @models .permalink
21+ @set_attr ('attribute' , 'value' )
22+ def url_with_attribute (self ):
23+ "Returns the URL for this guitarist and holds an attribute"
24+ return ('guitarist_detail' , [self .slug ])
Original file line number Diff line number Diff line change @@ -16,3 +16,12 @@ def test_wrapped_docstring(self):
1616 "Methods using the @permalink decorator retain their docstring."
1717 g = Guitarist (name = 'Adrien Moignard' , slug = 'adrienmoignard' )
1818 self .assertEqual (g .url .__doc__ , "Returns the URL for this guitarist." )
19+
20+ def test_wrapped_attribute (self ):
21+ """
22+ Methods using the @permalink decorator can have attached attributes
23+ from other decorators
24+ """
25+ g = Guitarist (name = 'Adrien Moignard' , slug = 'adrienmoignard' )
26+ self .assertTrue (hasattr (g .url_with_attribute , 'attribute' ))
27+ self .assertEqual (g .url_with_attribute .attribute , 'value' )
You can’t perform that action at this time.
0 commit comments