[Answer]-Matrix of Foreign Keys and free textfields in Django

1đź‘Ť

âś…

One model with 24 exact fields is not very good DB design. I don’t know if this may be possible, but what happens if you start using 32-well plates? Instead, I would create a Hole/Well model with a foreign key to the Sample and any other data you might assign to it:

class Well(models.Model):
    sample = models.ForeignKey('Sample')
    letter = models.CharField(max_length=1)
    position = models.IntegerField()
    is_filled = models.BooleanField(default=True)
    ...

With this approach you can get a Sample’s wells, count them or annotate them. You can even leave out the “unfilled” ones if you want.

👤Leticia

Leave a comment