I'm looking for some input on Model design and Form handling. The client can specify a set of TestPoint that they will add Trials to. The number of Trial that should be captured for every TestPoint depends on a Source.total_trials field.
class Source(Model):
total_trials = IntegerField()
class TestPoint(Model):
source = FK(Source)
value = FloatField()
class Trial(Model):
testpoint = FK(TestPoint)
value = FloatField(null=True)
The end result is an NxM matrix where the first column depicts all the TestPoint.value and every subsequent column is the Trial "Number" and its value. See this representation of how it currently looks:
# Model Related Question
The first glaring problem in the above model representation is a missing Trial number field, if TestPoint1 Trial4 was set and the previous ones werent, we need to make sure the persistence captures which trial this is. The second issue I'm noticing is how tiny the Trial model is, unlike the other two models, the Trial model is really that small, it only captures a "Value".
Question - I'm contemplating dropping the Trial model altogether and making trials a mere Array field on the TestPoint model with a default value of [0.0, 0.0, 0.0, 0.0, 0.0] this will tackle the ordering issue and drop an unnecessary model that will grow indefinitely and not carry anything more than a value. Thoughts? Any other idea?
# Form Related Question
The way the form is being built assigns text input names according to what they represent:
test points = tp_1, tp_2, tp_3, ...
trials = tp_1_1, tp_1_2, ... tp_1_3 ...
and the html display is via a CSS grid that is created to suspiciously look like a inline django form.
Question - Since the number of trials is dynamic, would you use a django formset for this, instead of handling it manually the way I'm doing?