4 from django.db import models
6 from contact.models import Contact
11 class Submission(models.Model):
12 contact = models.ForeignKey(Contact, null = True)
13 key = models.CharField(max_length = 30, unique = True)
14 first_name = models.CharField(max_length = 100)
15 last_name = models.CharField(max_length = 100)
16 email = models.EmailField(max_length = 100, unique = True)
17 answers = models.CharField(max_length = 65536, null = True, blank = True)
18 key_sent = models.BooleanField(default = False)
21 def generate_key(cls):
23 while not key or key in [record['key'] for record in cls.objects.values('key')]:
24 key = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for i in range(30))
28 def create(cls, first_name, last_name, email, key = None, contact = None):
31 key = key if key else Submission.generate_key(),
32 first_name = first_name,
33 last_name = last_name,
41 class Attachment(models.Model):
42 submission = models.ForeignKey(Submission)
43 name = models.CharField(max_length=100)
44 file = models.FileField(upload_to = 'wtem/attachment')