jeudi 2 avril 2015

Django composite forms - how do I build and save them?

I am trying to build a form that would provide report tracking. Report itself is ProjectReport class that links instances of all available ReportAtoms. Each ReportAtom is a combination of RAGItem (like "Progress", "Risks", "Resources") and RAGMarker ("Green", "Red"):



class ProjectStatus(CoreBase):
report_project = models.ForeignKey('Project')
report_items = models.ManyToManyField('RAGReportAtom')
report_date = models.DateTimeField(default=datetime.now())

class RAGReportAtom(CoreBase):
item = models.ForeignKey(DicRAGItem)
marker = models.ForeignKey(DicRAGMarker)
comments = models.TextField(null=True, blank=True)

class DicRAGItem(DicCoreBase):
name = models.CharField(max_length=64, unique=True)
description = models.TextField(null=True, blank=True)
is_used_for_portfolio = models.BooleanField(default=False)
is_used_for_project = models.BooleanField(default=True)
is_used_for_milestone = models.BooleanField(default=True

class DicRAGMarker(DicCoreBase):
name = models.CharField(max_length=16, unique=True)
color_code = models.CharField(max_length=7, unique=True)
icon = models.FileField(upload_to='RAG_SIMPLE_ICONS', null=True, blank=True)


This is how this can be represented graphically:


enter image description here


So what I am trying to do here is basically this:



  1. Get list of all available report items (things reported on)

  2. Build a form that will display all report items and let users select a marker for each

  3. Users can leave comments

  4. When form is submitted I create as many report atoms as I ended up having (combinations of items and markers) and a ProjectReport instance that links all them.


Something similar to this:


enter image description here


Is this going to be possible to generate this form with Django.forms and crispy? I am using django rest framework for most forms - perhaps I could make use of this, too?


Aucun commentaire:

Enregistrer un commentaire