Skip to content

Instantly share code, notes, and snippets.

@jimrollenhagen
Created June 24, 2012 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimrollenhagen/2985369 to your computer and use it in GitHub Desktop.
Save jimrollenhagen/2985369 to your computer and use it in GitHub Desktop.
property example
class Thing(models.model):
something = models.CharField(null=True)
# ...
@property
def something_display(self):
if self.something is None:
return 'something else'
return self.something
#####
>>> thing = Thing()
>>> thing.something
None
>>> thing.something_display
'something else'
>>> thing.something = 'yay'
>>> thing.something
'yay'
>>> thing.something_display
'yay'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment