Created
March 18, 2014 18:29
-
-
Save bulv1ne/9626369 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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