regluit/booxtream/models.py

27 lines
818 B
Python
Raw Normal View History

from datetime import timedelta, datetime
from django.db import models
class Boox(models.Model):
"""
keeps a record of a file that's been watermarked
"""
2018-06-08 19:17:39 +00:00
download_link_epub = models.URLField(null=True)
download_link_mobi = models.URLField(null=True)
referenceid = models.CharField(max_length=32)
2018-06-08 19:17:39 +00:00
downloads_remaining = models.PositiveSmallIntegerField(default=0)
expirydays = models.PositiveSmallIntegerField()
created = models.DateTimeField(auto_now_add=True)
2018-06-08 19:17:39 +00:00
@property
def expired(self):
return self.created+timedelta(days=self.expirydays) < datetime.now()
2018-06-08 19:17:39 +00:00
def download_link(self, format):
if format == 'epub':
return self.download_link_epub
elif format == 'mobi':
return self.download_link_mobi
2018-06-08 19:17:39 +00:00
return None