-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmodels.py
42 lines (32 loc) · 1.48 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
class Email(models.Model):
create_date = models.DateTimeField(auto_now_add=True)
subject = models.TextField(blank=True)
body = models.TextField(blank=True)
content_subtype = models.CharField(max_length=254)
from_email = models.CharField(max_length=254, blank=True)
to = models.TextField(blank=True)
cc = models.TextField(blank=True)
bcc = models.TextField(blank=True)
headers = models.TextField(blank=True)
def __str__(self):
return '{} - {}, {}'.format(self.subject, self.to, self.create_date)
@python_2_unicode_compatible
class EmailAlternative(models.Model):
email = models.ForeignKey(Email, on_delete=models.CASCADE, related_name='alternatives')
content = models.TextField(blank=True)
mimetype = models.CharField(max_length=254, blank=True)
def __str__(self):
return '{}: alternative {}'.format(self.email, self.mimetype)
@python_2_unicode_compatible
class EmailAttachment(models.Model):
email = models.ForeignKey(Email, on_delete=models.CASCADE, related_name='attachments')
filename = models.CharField(max_length=1000, blank=True)
mimetype = models.CharField(max_length=254, blank=True)
file = models.FileField(upload_to='db_email_backend')
def __str__(self):
return '{}: attachment {}'.format(self.email, self.filename)