1. Based on your bottom example, metric items have an Indicator. That should be a ForeignKey
relationship:
class DicProjectStatusRAGIndicator(DicCoreBase):
text_marker = models.CharField(max_length=64)
color_marker = models.CharField(max_length=6)
icon = models.FileField(upload_to='RAG_icons')
class DicProjectStatusRAGReportItem(DicCoreBase):
name = models.CharField(max_length=32)
description = models.TextField()
indicator = models.ForeignKey(DicProjectStatusRAGIndicator)
Assuming 'fixed all major defects' is the description
field of Free Text, then DicProjectFreeTextReportItem
is fine.
2. Since a project report record can have multiple metric items and free text items, that should be a Many-to-many
relationship:
class ProjectReportRecord(models.Model):
project = models.ForeignKey(Project, related_name='reports')
metrics = models.ManyToManyField(DicProjectStatusRAGReportItem)
free_texts = models.ManyToManyField(DicProjectFreeTextReportItem)
Now, referring to your example above and our Django models we've made, we can get to that information like so:
p = Project.objects.get(pk=1)
record = p.reports.all()[0]
print record.metrics.all().values_list('name', flat=True)
# prints ['progress', 'quality']
print record.metrics.get(name='progress').indicator.text_marker
# prints 'green'