bia-fitness/profiles/models.py

32 lines
938 B
Python
Raw Normal View History

2015-04-06 22:35:51 +00:00
from django.db import models
from django.contrib.auth.models import User
2015-04-10 16:28:25 +00:00
from django.contrib.postgres.fields import ArrayField
from common import to_lb
2015-04-06 22:35:51 +00:00
UNITS = (
('m', 'Metric (kg)'),
2015-04-10 16:28:25 +00:00
('i', 'Imperial (lb)'),
2015-04-06 22:35:51 +00:00
)
2015-04-10 16:28:25 +00:00
2015-04-06 22:35:51 +00:00
class Profile(models.Model):
user = models.OneToOneField(User, related_name='profile')
2015-04-10 16:28:25 +00:00
lifting_units = models.CharField(max_length=1, choices=UNITS, default='i')
plate_pairs = ArrayField(models.DecimalField(max_digits=7, decimal_places=3),
default=['45','45','25','10','5','5','2.5','1.25'])
class Bar(models.Model):
user = models.OneToOneField(User, related_name='bar')
name = models.CharField(max_length=100)
weight_kg = models.DecimalField(max_digits=7, decimal_places=3)
def __str__(self):
return '{} ({}lb / {}kg)'.format(self.name, self.weight_kg, self.weight_lb)
@property
def weight_lb(self):
return to_lb(self.weight_kg)