from django.db import models from engagements.models import EngagementEffort, Organisation class Common(models.Model): date_created = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True) class Meta: abstract = True class Instrument(Common): "JSP 628, JSP 440, the ONR ones, etc" name = models.CharField(max_length=512, null=False, blank=False) long_title = models.CharField(max_length=1024, null=True, blank=True) designator = models.CharField(max_length=3, null=True, blank=True) owner = models.ForeignKey(Organisation, null=False, blank=False, on_delete=models.CASCADE) link = models.URLField(max_length=1024, null=True, blank=True) def __str__(self): return self.name class Meta: verbose_name_plural = "Instruments" class SubInstrument(Common): "DSCs, Chapters, Supplements, Leaflets..." choices = ( ("DSC", "Defence Security Condition (DSC)"), ("DSYAP", "Defence Security Assessment Principle (DSyAP)"), ("DSTAIG", "Defence Security Testing And I Don't Know (DSTAIG)"), ) is_guidance = models.BooleanField(null=True, blank=True, default=False) itype = models.CharField(choices=choices, max_length=6, verbose_name="Instrument Type") title = models.CharField(max_length=512, null=False, blank=False) parent = models.ForeignKey(Instrument, on_delete=models.CASCADE, verbose_name="Parent Instrument") description = models.TextField(null=True, blank=True) rationale = models.TextField(null=True, blank=True) relative = models.ManyToManyField("self") short = models.CharField(max_length=10, null=True, blank=True) def effort(self): return EngagementEffort.objects.filter(sub_instruments__contains=self) def effort_for_org(self, org): eff = EngagementEffort.objects.filter(engagement__external_party=org).filter(effort_type="REGULATION") return sum(e.effort_total_hours() for e in eff) def __str__(self): return self.title class Meta: verbose_name_plural = "Sub Instruments"