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)
20 def generate_key(cls):
22 while not key or key in [record['key'] for record in cls.objects.values('key')]:
23 key = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for i in range(30))
27 def create(cls, first_name, last_name, email, key = None, contact = None):
30 key = key if key else Submission.generate_key(),
31 first_name = first_name,
32 last_name = last_name,
40 class Attachment(models.Model):
41 submission = models.ForeignKey(Submission)
42 name = models.CharField(max_length=100)
43 file = models.FileField(upload_to = 'wtem/attachment')