Skip to content

Commit

Permalink
Fixed previous field, and added models that are yet to be migrated
Browse files Browse the repository at this point in the history
  • Loading branch information
ineshbose committed Nov 8, 2021
1 parent f333183 commit 471dd74
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/backend/main/migrations/0001_initial.py
@@ -1,4 +1,4 @@
# Generated by Django 3.2.8 on 2021-11-07 18:53
# Generated by Django 3.2.8 on 2021-11-08 13:46

from django.db import migrations, models
import django.utils.timezone
Expand Down Expand Up @@ -28,7 +28,7 @@ class Migration(migrations.Migration):
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('picture', models.ImageField(blank=True, upload_to=main.models.PathAndRename('profile_images/'), verbose_name='profile picture')),
('age', models.ImageField(blank=True, null=True, upload_to='', verbose_name='age')),
('age', models.IntegerField(blank=True, null=True, verbose_name='age')),
('height', models.FloatField(blank=True, null=True, verbose_name='height')),
('weight', models.FloatField(blank=True, null=True, verbose_name='weight')),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
Expand Down
61 changes: 56 additions & 5 deletions src/backend/main/models.py
Expand Up @@ -92,12 +92,9 @@ class User(AbstractBaseUser, PermissionsMixin):
Username (email) and password are required. Other fields are optional.
"""
#username_validator = UnicodeUsernameValidator()

email = models.EmailField(
_('email address'),
unique=True,
#validators=[username_validator],
error_messages={
'unique': _("An account with that email already exists."),
},
Expand Down Expand Up @@ -132,7 +129,7 @@ class User(AbstractBaseUser, PermissionsMixin):
upload_to=PathAndRename('profile_images/'),
blank=True,
)
age = models.ImageField(_('age'), **NULL_BLANK)
age = models.IntegerField(_('age'), **NULL_BLANK)
height = models.FloatField(_('height'), **NULL_BLANK)
weight = models.FloatField(_('weight'), **NULL_BLANK)

Expand Down Expand Up @@ -160,4 +157,58 @@ def get_short_name(self):

def email_user(self, subject, message, from_email=None, **kwargs):
"""Send an email to this user."""
send_mail(subject, message, from_email, [self.email], **kwargs)
send_mail(subject, message, from_email, [self.email], **kwargs)


class PortionItem(models.Model):
"""
A class representing a food/portion item that can be tracked.
"""
name = models.CharField(_('item name'), max_length=150)
is_default = models.BooleanField(_('is default?'), default=False)

class Meta:
verbose_name = _('portion item')
verbose_name_plural = _('portion items')

def __str__(self):
return self.name


class Frequency(models.IntegerChoices):
"""
Options for the frequency on how often the log count should refresh.
"""
DAILY = 1, _('Daily')
WEEKLY = 7, _('Weekly')


class TrackItem(models.Model):
"""
A class representing a portion item that a user wants to track.
"""
item = models.ForeignKey(PortionItem, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE)
target = models.IntegerField(_('target'), default=1)
order = models.IntegerField(_('order'), **NULL_BLANK)
frequency = models.IntegerChoices(_('frequency'), default=Frequency.DAILY)

class Meta:
ordering = ['order']

def __str__(self):
return super().__str__()


class UserLog(models.Model):
"""
A class representing a log.
"""
item = models.ForeignKey(TrackItem)
timestamp = models.DateTimeField()

class Meta:
ordering = ['timestamp']

def __str__(self):
return super().__str__()

0 comments on commit 471dd74

Please sign in to comment.