comparison gpp/potd/models.py @ 535:4021ea1045f7

Adding import commands for the 1.0 POTD & comments.
author Brian Neal <bgneal@gmail.com>
date Sat, 31 Dec 2011 21:34:17 +0000
parents ff67946fd4b0
children
comparison
equal deleted inserted replaced
534:98f5facc0030 535:4021ea1045f7
1 """ 1 """
2 Models for the Photo Of The Day (POTD) application. 2 Models for the Photo Of The Day (POTD) application.
3 3
4 """ 4 """
5 import datetime
5 import os 6 import os
6 from PIL import ImageFile 7 from PIL import ImageFile
7 from PIL import Image 8 from PIL import Image
8 try: 9 try:
9 from cStringIO import StringIO 10 from cStringIO import StringIO
30 photo = models.ImageField(upload_to='potd/%Y/%m/%d') 31 photo = models.ImageField(upload_to='potd/%Y/%m/%d')
31 thumb = models.ImageField(upload_to='potd/%Y/%m/%d/thumbs', blank=True, null=True) 32 thumb = models.ImageField(upload_to='potd/%Y/%m/%d/thumbs', blank=True, null=True)
32 caption = models.CharField(max_length=128) 33 caption = models.CharField(max_length=128)
33 description = models.TextField() 34 description = models.TextField()
34 user = models.ForeignKey(User) 35 user = models.ForeignKey(User)
35 date_added = models.DateField(auto_now_add=True) 36 date_added = models.DateField()
36 potd_count = models.IntegerField(default=0) 37 potd_count = models.IntegerField(default=0)
37 38
38 class Meta: 39 class Meta:
39 ordering = ('-date_added', '-caption') 40 ordering = ('-date_added', '-caption')
40 41
46 return ('potd-archive', [str(self.id)]) 47 return ('potd-archive', [str(self.id)])
47 48
48 def save(self, *args, **kwargs): 49 def save(self, *args, **kwargs):
49 if not self.pk: 50 if not self.pk:
50 self.generate_thumb() 51 self.generate_thumb()
52 self.date_added = datetime.datetime.now()
51 53
52 super(Photo, self).save(*args, **kwargs) 54 super(Photo, self).save(*args, **kwargs)
53 55
54 def can_comment_on(self): 56 def can_comment_on(self):
55 return Current.objects.get_current_id() == self.id 57 return Current.objects.get_current_id() == self.id
167 seq = models.CommaSeparatedIntegerField(max_length=4096) 169 seq = models.CommaSeparatedIntegerField(max_length=4096)
168 170
169 objects = SequenceManager() 171 objects = SequenceManager()
170 172
171 def __unicode__(self): 173 def __unicode__(self):
172 return self.seq 174 return u'POTD Sequence %d' % self.id
173 175
174 class Meta: 176 class Meta:
175 verbose_name_plural = 'Sequence' 177 verbose_name_plural = 'Sequence'