comparison gpp/weblinks/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 7e8d2dda99e3
children 368d731af479
comparison
equal deleted inserted replaced
276:8a46843c258f 277:d424b8bae71d
34 category = models.ForeignKey(Category) 34 category = models.ForeignKey(Category)
35 title = models.CharField(max_length=128) 35 title = models.CharField(max_length=128)
36 url = models.URLField(verify_exists=False, db_index=True) 36 url = models.URLField(verify_exists=False, db_index=True)
37 description = models.TextField(blank=True) 37 description = models.TextField(blank=True)
38 user = models.ForeignKey(User) 38 user = models.ForeignKey(User)
39 date_added = models.DateField() 39 date_added = models.DateTimeField(db_index=True)
40 update_date = models.DateTimeField(db_index=True, blank=True)
40 41
41 class Meta: 42 class Meta:
42 abstract = True 43 abstract = True
43 44
44 45
54 class Meta: 55 class Meta:
55 ordering = ('title', ) 56 ordering = ('title', )
56 57
57 def __unicode__(self): 58 def __unicode__(self):
58 return self.title 59 return self.title
60
61 def save(self, *args, **kwargs):
62 if not self.pk:
63 if not self.date_added:
64 self.date_added = datetime.datetime.now()
65 self.update_date = self.date_added
66 else:
67 self.update_date = datetime.datetime.now()
68
69 super(Link, self).save(*args, **kwargs)
59 70
60 @models.permalink 71 @models.permalink
61 def get_absolute_url(self): 72 def get_absolute_url(self):
62 return ('weblinks-link_detail', [str(self.id)]) 73 return ('weblinks-link_detail', [str(self.id)])
63 74
79 return self.title 90 return self.title
80 91
81 def save(self, *args, **kwargs): 92 def save(self, *args, **kwargs):
82 if not self.pk: 93 if not self.pk:
83 self.date_added = datetime.datetime.now() 94 self.date_added = datetime.datetime.now()
95 self.update_date = self.date_added
96 else:
97 self.update_date = datetime.datetime.now()
98
84 super(PendingLink, self).save(*args, **kwargs) 99 super(PendingLink, self).save(*args, **kwargs)
85 100
86 101
87 class FlaggedLinkManager(models.Manager): 102 class FlaggedLinkManager(models.Manager):
88 103