oacpl/newsletters/models.py

37 lines
981 B
Python
Raw Normal View History

2017-08-18 21:25:17 -04:00
from django.db import models
from django.contrib.auth.admin import User
2017-09-14 11:52:49 -04:00
from django.utils import timezone
2017-08-18 21:25:17 -04:00
2018-01-05 19:12:27 -05:00
from tinymce.models import HTMLField
2017-08-18 21:25:17 -04:00
2018-02-26 18:13:02 -05:00
class Attachment(models.Model):
file = models.FileField(upload_to='Newsletter')
def name(self):
return self.file.name.replace('Newsletter/', '')
def __str__(self):
return self.file.name
2017-08-18 21:25:17 -04:00
class Newsletter(models.Model):
2018-01-05 19:12:27 -05:00
body = HTMLField()
2017-08-18 21:25:17 -04:00
created = models.DateTimeField(auto_now_add=True)
2018-05-24 16:11:59 -04:00
creator = models.ForeignKey(User, on_delete=models.DO_NOTHING)
2017-09-14 11:52:49 -04:00
publish = models.DateTimeField(default=timezone.now)
sent = models.BooleanField(default=False)
2017-08-18 21:25:17 -04:00
subject = models.CharField(max_length=255)
2018-05-24 16:14:08 -04:00
attachments = models.ManyToManyField(Attachment, blank=True)
2017-08-18 21:25:17 -04:00
def __str__(self):
return self.subject
2017-08-18 23:23:03 -04:00
class Subscriber(models.Model):
email = models.EmailField(unique=True)
2018-01-14 19:32:00 -05:00
date = models.DateField(auto_now_add=True)
2017-08-18 23:23:03 -04:00
def __str__(self):
return self.email