Added valid property to VoucherModel.

This commit is contained in:
Marcus Scholz 2020-09-18 21:02:07 +02:00
parent e698f3b224
commit a3b123a207
1 changed files with 5 additions and 0 deletions

View File

@ -15,6 +15,7 @@ from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.core.validators import MaxValueValidator, MinValueValidator
from django.utils import timezone
from easy_thumbnails.fields import ThumbnailerImageField
from easy_thumbnails.files import get_thumbnailer
from taggit.managers import TaggableManager
@ -106,6 +107,10 @@ class Voucher(models.Model):
created_when = models.DateTimeField(auto_now_add=True)
expires_when = models.DateTimeField()
@property
def valid(self):
return timezone.now() <= self.expires_when
def __str__(self):
return "Voucher " + str(self.pk)