view bns_website/reviews/models.py @ 108:9ca05ec9b64e tip

Update buy links.
author Brian Neal <bgneal@gmail.com>
date Sat, 27 Sep 2014 12:36:06 -0500
parents 2598bc18b6fb
children
line wrap: on
line source
"""
Models for the reviews application.

"""
from django.db import models
from datetime import timedelta, datetime
from django.core.urlresolvers import reverse

class Review(models.Model):
    """
    This model represents all the info we store about each review.
    """
    date = models.DateTimeField(auto_now_add=True)
    title = models.CharField(max_length=200)
    reviewer = models.CharField(max_length=200)
    review_site = models.CharField(max_length=200, blank=True)
    review_url = models.URLField(verify_exists=False, max_length=256, blank=True)
    review = models.TextField()

    class Meta:
        verbose_name_plural = "Reviews"
        ordering = ['-date']

    def __unicode__(self):
        return self.reviewer

    def is_new(self):
        if datetime.now() - self.date <= timedelta(days=30):
            return True
        return False

    def get_absolute_url(self):
        return reverse('reviews') + '#review%d' % self.id