comparison gpp/downloads/models.py @ 277:d424b8bae71d

Fixing #128 and #129. Add elsewhere weblinks to search content. Add support for haystack's get_update_field() method.
author Brian Neal <bgneal@gmail.com>
date Sat, 02 Oct 2010 23:24:39 +0000
parents 27bee3ac85e6
children 639cfdf59167
comparison
equal deleted inserted replaced
276:8a46843c258f 277:d424b8bae71d
54 category = models.ForeignKey(Category) 54 category = models.ForeignKey(Category)
55 description = models.TextField() 55 description = models.TextField()
56 html = models.TextField(blank=True) 56 html = models.TextField(blank=True)
57 file = models.FileField(upload_to=download_path) 57 file = models.FileField(upload_to=download_path)
58 user = models.ForeignKey(User) 58 user = models.ForeignKey(User)
59 date_added = models.DateTimeField() 59 date_added = models.DateTimeField(db_index=True)
60 ip_address = models.IPAddressField('IP Address') 60 ip_address = models.IPAddressField('IP Address')
61 update_date = models.DateTimeField(db_index=True, blank=True)
61 62
62 class Meta: 63 class Meta:
63 abstract = True 64 abstract = True
64 65
65 def size(self): 66 def size(self):
78 return self.title 79 return self.title
79 80
80 def save(self, *args, **kwargs): 81 def save(self, *args, **kwargs):
81 if not self.pk: 82 if not self.pk:
82 self.date_added = datetime.datetime.now() 83 self.date_added = datetime.datetime.now()
84 self.update_date = self.date_added
85 else:
86 self.update_date = datetime.datetime.now()
87
83 self.html = site_markup(self.description) 88 self.html = site_markup(self.description)
84 super(PendingDownload, self).save(*args, **kwargs) 89 super(PendingDownload, self).save(*args, **kwargs)
85 90
86 91
87 class Download(DownloadBase): 92 class Download(DownloadBase):
101 @models.permalink 106 @models.permalink
102 def get_absolute_url(self): 107 def get_absolute_url(self):
103 return ('downloads-details', [str(self.id)]) 108 return ('downloads-details', [str(self.id)])
104 109
105 def save(self, *args, **kwargs): 110 def save(self, *args, **kwargs):
111 if not self.pk:
112 self.date_added = datetime.datetime.now()
113 self.update_date = self.date_added
114 else:
115 self.update_date = datetime.datetime.now()
116
106 self.html = site_markup(self.description) 117 self.html = site_markup(self.description)
107 super(Download, self).save(*args, **kwargs) 118 super(Download, self).save(*args, **kwargs)
108 119
109 def vote(self, vote_value): 120 def vote(self, vote_value):
110 """receives a vote_value and updates internal score accordingly""" 121 """receives a vote_value and updates internal score accordingly"""