Search Results

Search found 3 results on 1 pages for 'bitbutter'.

Page 1/1 | 1 

  • How can I stop sorl thumbnail from breaking with very long filenames?

    - by bitbutter
    I've noticed that when working with SORL thumbnail, sometimes a user will upload an image with a very long filename, longer than the varfield in the database can hold. The name gets truncated in the database and the project gives errors whenever the image is requested. Is there a smart and safe way to have django automatically truncate long filenames in sorl uploads (prior to saving them in the database) to prevent this sort of thing? As reference, here's how the relevant model from my current project looks: class ArtistImage(models.Model): artist = models.ForeignKey(Artist) position = models.IntegerField() image = ThumbnailField( thumbnail_tag='<span class="artistimagewrapper"><img class="artistimage" src="%(src)s" width="%(width)s" height="%(height)s"></span>', upload_to='uploaded_images/artistimages', size=(900,900), quality=100, options={'crop': 'center'}, extra_thumbnails={ 'small':{ 'size':(92,92), 'quality':100, 'options':{'crop': 'center'}, } } ) class Meta: ordering = ('image',) def __unicode__(self): return (u"%s" % self.image)

    Read the article

  • Django: way to test what class a generic relation content_object is?

    - by bitbutter
    In my project I have a class, NewsItem. Instances of NewsItem act like a wrapper. They can be associated with either an ArtWork instance, or an Announcement instance. Here's how the NewsItem model looks: class NewsItem(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') date = models.DateTimeField(default=datetime.datetime.now,) class Meta: ordering = ('-date',) def __unicode__(self): return (self.title()) In a template I'm dealing with a NewsItem instance, and would like to output a certain bunch of html it it's 'wrapping' an Artwork instance, and a different bunch of html if it's wrapping an Announcement instance. Could someone explain how I can write a conditional to test for this? My first naive try looked like this: {% if news_item.content_object.type=='Artwork' %}do this{% else %}do that{% endif %}

    Read the article

1