Skip to content

Instantly share code, notes, and snippets.

@bulv1ne
Created March 18, 2014 18:29
Show Gist options
  • Save bulv1ne/9626369 to your computer and use it in GitHub Desktop.
Save bulv1ne/9626369 to your computer and use it in GitHub Desktop.
class Photo(models.Model):
photo = models.ImageField(upload_to='photos')
@set_attributes(short_description='Image', allow_tags=True)
def image_tag(self):
if not self.photo:
return u''
return u'<img width="100" src="/media/%s" />' % self.photo
class Photo(models.Model):
photo = models.ImageField(upload_to='photos')
def image_tag(self):
if not self.photo:
return u''
return u'<img width="100" src="/media/%s" />' % self.photo
image_tag.short_description = 'Image'
image_tag.allow_tags = True
def set_attributes(**kwargs):
def decorator(f):
for key, value in kwargs.iteritems():
setattr(f, key, value)
return f
return decorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment