реалізація в моделі:
from django.utils.timesince import timesince as timesince_
class Review(models.Model):
to_user = models.ForeignKey('users.Profile', verbose_name=_('from user'), \
related_name="review_to_user")
from_user = models.ForeignKey('users.Profile', verbose_name=_('to user'), \
related_name="review_from_user")
timestamp = models.DateTimeField(_('timestamp'), auto_now_add=True)
class Meta:
verbose_name = _('rating')
verbose_name_plural = _('ratings')
ordering = ['timestamp']
def timesince(self, now=None):
return timesince_(self.timestamp, now)
def __unicode__(self):
return unicode("Review to %s from %s %s ago" % \
(self.to_user, self.from_user, self.timesince()))
def get_absolute_url(self):
return reverse('reviews_reviews', args=[self.to_user])
Немає коментарів:
Дописати коментар