4 from django.db import models
6 from contact.models import Contact
9 class Submission(models.Model):
10 contact = models.ForeignKey(Contact, null = True)
11 key = models.CharField(max_length = 30, unique = True)
12 first_name = models.CharField(max_length = 100)
13 last_name = models.CharField(max_length = 100)
14 email = models.EmailField(max_length = 100, unique = True)
15 answers = models.CharField(max_length = 65536, null = True, blank = True)
18 def generate_key(cls):
20 while not key and key in [record['key'] for record in cls.objects.values('key')]:
21 key = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for i in range(30))
25 def create(cls, first_name, last_name, email, key = None, contact = None):
28 key = key if key else Submission.generate_key(),
29 first_name = first_name,
30 last_name = last_name,
38 class Attachment(models.Model):
39 submission = models.ForeignKey(Submission)
40 name = models.CharField(max_length=100)
41 file = models.FileField(upload_to = 'wtem/attachment')