2019-01-20 06:39:07 +00:00
|
|
|
from django.db import models
|
2019-01-23 00:38:09 +00:00
|
|
|
from django.conf import settings
|
2019-02-01 00:55:11 +00:00
|
|
|
import datetime
|
2019-01-20 06:39:07 +00:00
|
|
|
|
2019-01-20 22:39:11 +00:00
|
|
|
class Report(models.Model):
|
2019-01-23 00:38:09 +00:00
|
|
|
user_id = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
2019-01-20 22:39:11 +00:00
|
|
|
title = models.CharField(max_length=128)
|
2019-02-01 00:55:11 +00:00
|
|
|
date_created = models.DateTimeField('date created', default=datetime.date.today)
|
|
|
|
date_submitted = models.DateTimeField('date submitted', default=datetime.date.today)
|
2019-01-23 00:38:09 +00:00
|
|
|
submitted = models.BooleanField(default=False)
|
2019-01-20 06:39:07 +00:00
|
|
|
|
2019-01-25 22:37:03 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.title
|
|
|
|
|
2019-01-20 22:39:11 +00:00
|
|
|
class Section(models.Model):
|
|
|
|
report_id = models.ForeignKey(Report, on_delete=models.CASCADE)
|
2019-02-01 00:55:11 +00:00
|
|
|
auto_submit = models.BooleanField()
|
|
|
|
required = models.BooleanField()
|
2019-01-20 22:39:11 +00:00
|
|
|
completed = models.BooleanField()
|
|
|
|
title = models.CharField(max_length=256)
|
|
|
|
html_description = models.TextField()
|
|
|
|
number = models.IntegerField()
|
|
|
|
|
2019-01-25 22:37:03 +00:00
|
|
|
def __str__(self):
|
|
|
|
return "{0}(#{1})".format(self.title, self.number)
|
|
|
|
|
2019-01-20 22:39:11 +00:00
|
|
|
class Field(models.Model):
|
|
|
|
section_id = models.ForeignKey(Section, on_delete=models.CASCADE)
|
2019-02-01 00:55:11 +00:00
|
|
|
label = models.CharField(max_length=512)
|
2019-01-20 22:39:11 +00:00
|
|
|
number = models.IntegerField()
|
|
|
|
type = models.CharField(max_length=128)
|
2019-01-23 00:38:09 +00:00
|
|
|
completed = models.BooleanField(default=False)
|
2019-02-01 00:55:11 +00:00
|
|
|
data_bool = models.BooleanField(default=False)
|
|
|
|
data_decimal = models.DecimalField(max_digits=9,decimal_places=2, null=True, blank=True)
|
|
|
|
data_date = models.DateField(default=datetime.date.today)
|
|
|
|
data_file = models.FileField(upload_to='uploads/%Y/%m/%d/', max_length=512, null=True, blank=True)
|
|
|
|
data_string = models.TextField(default='', blank=True)
|
|
|
|
data_integer = models.IntegerField(default=0, blank=True)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
if self.type == "boolean":
|
|
|
|
if self.data_bool:
|
|
|
|
return "True"
|
|
|
|
else:
|
|
|
|
return "False"
|
|
|
|
elif self.type == "decimal":
|
|
|
|
return "{}".format(self.data_decimal)
|
|
|
|
elif self.type == "date":
|
|
|
|
return "{}".format(self.data_date)
|
|
|
|
elif self.type == "file":
|
|
|
|
return "{}".format(self.data_file)
|
|
|
|
elif self.type == "string":
|
|
|
|
return "{}".format(self.data_string)
|
|
|
|
elif self.type == "integer":
|
|
|
|
return "{}".format(self.data_integer)
|