Thursday, August 28, 2014

New user - struggling with database design

Hi all,

I am building an app to track my home brewing.

I have two tables, one for vessels, and another for brews.

I want the Brew table to have a pick-list, relation to Vessels so I can say what vessel the brew is in.

I also want to render a table that shows all Vessels and what Brew is in each. There should be a one-to-one relationship until the Brew is 'Kicked', which could be a vessel or maybe a null value in the Brew table.

My code currently doesn't work, but looks something like this:

class Vessel(models.Model):
    Name = models.CharField(max_length=20)
    Gallons = models.DecimalField(max_digits=4, decimal_places=2, null=True, blank=True)
    Weight = models.DecimalField(max_digits=4, decimal_places=2, null=True, blank=True)
    CurrentBrew  = models.ForeignKey(Brew, db_column='Vessel')  <--------------------------------------this is what I'm trying to add
    def __unicode__(self):
        return self.Name

class Brew(models.Model):
    Name = models.CharField(max_length=40, null=True, default='TBD')
    InformalName = models.CharField(max_length=40)
    Status = models.IntegerField(max_length=1, choices=STATUS_CHOICES, default=1, null=False, blank=False)
    Gallons = models.DecimalField(max_digits=4, decimal_places=2, null=True, blank=True)
    Vessel = models.ForeignKey(Vessel)
    Style = models.ForeignKey(Style)
    Event = models.CharField(max_length=40, null=True, blank=True)

In this model, which I'm not sure is the best way to do it, the Vessel class does not yet know about the Brew model that is below it.

I'm starting to grasp this language (and love it, coming from doing asp/sql several years ago) but I'm stuck here. Help!

You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment