X-Git-Url: https://code.kerkeslager.com/?p=climbing.kerkeslager.com;a=blobdiff_plain;f=src%2Fnutrition%2Fmodels.py;h=03840fbb5484aba594871801f3c68b0111ad23b4;hp=ba7d41551d67145cd99dd33efbfa568aefb0b1a5;hb=af1a3a283688e74a6e7868395cf2a507dcd2e0f4;hpb=3977607665b62dae546113a3888fd3588d743283 diff --git a/src/nutrition/models.py b/src/nutrition/models.py index ba7d415..03840fb 100644 --- a/src/nutrition/models.py +++ b/src/nutrition/models.py @@ -1,6 +1,27 @@ +from django.contrib.auth.models import User from django.db import models class Food(models.Model): - name = models.TextField(max_length=64) - brand = models.TextField(max_length=64) + name = models.CharField(max_length=64) + brand = models.CharField(max_length=64) calories = models.PositiveIntegerField() + + def __str__(self): + return '{} ({})'.format(self.name, self.brand) + +WEIGHT_UNITS_CHOICES = ( + ('kgs', 'kgs'), + ('lbs', 'lbs'), +) + +class WeightRecord(models.Model): + user = models.ForeignKey(User, on_delete=models.CASCADE) + weight = models.PositiveIntegerField() + units = models.CharField(max_length=3, choices=WEIGHT_UNITS_CHOICES) + + def __str__(self): + return '{}: {}{}'.format( + self.user.username, + self.weight, + self.units, + )