-from django.db import models
from django.contrib.auth.models import User
+from django.db import models
class Area(models.Model):
name = models.CharField(max_length=64)
class FoodAdmin(admin.ModelAdmin):
pass
admin.site.register(models.Food, FoodAdmin)
+
+class WeightRecordAdmin(admin.ModelAdmin):
+ pass
+admin.site.register(models.WeightRecord, WeightRecordAdmin)
--- /dev/null
+# Generated by Django 4.0.3 on 2022-03-04 15:43
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ('nutrition', '0002_name_and_brand_as_char_fields'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='WeightRecord',
+ fields=[
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('weight', models.PositiveIntegerField()),
+ ('units', models.CharField(choices=[('kgs', 'kgs'), ('lbs', 'lbs')], max_length=3)),
+ ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
+ ],
+ ),
+ ]
+from django.contrib.auth.models import User
from django.db import models
class Food(models.Model):
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,
+ )