113 lines
8.4 KiB
Python
113 lines
8.4 KiB
Python
# Generated by Django 6.1.1 on 2026-10-03 18:39
|
|
|
|
import django.core.validators
|
|
import django.db.models.deletion
|
|
from django.conf import settings
|
|
from django.db import migrations, models
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
initial = True
|
|
|
|
dependencies = [
|
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
|
]
|
|
|
|
operations = [
|
|
migrations.CreateModel(
|
|
name='FoodProduct',
|
|
fields=[
|
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
('barcode', models.CharField(blank=True, db_index=True, max_length=64)),
|
|
('product_name', models.CharField(max_length=255)),
|
|
('brand', models.CharField(blank=True, max_length=255)),
|
|
('image_url', models.URLField(blank=True)),
|
|
('package_quantity', models.CharField(blank=True, max_length=100)),
|
|
('serving_size_text', models.CharField(blank=True, max_length=100)),
|
|
('serving_amount', models.DecimalField(blank=True, decimal_places=3, max_digits=10, null=True, validators=[django.core.validators.MinValueValidator(0.001)])),
|
|
('serving_unit', models.CharField(blank=True, choices=[('g', 'g'), ('ml', 'ml')], max_length=2)),
|
|
('base_unit', models.CharField(choices=[('g', 'g'), ('ml', 'ml')], default='g', max_length=2)),
|
|
('energy_kcal_100', models.DecimalField(blank=True, decimal_places=3, max_digits=10, null=True, validators=[django.core.validators.MinValueValidator(0)])),
|
|
('carbohydrates_100', models.DecimalField(blank=True, decimal_places=3, max_digits=10, null=True, validators=[django.core.validators.MinValueValidator(0)])),
|
|
('protein_100', models.DecimalField(blank=True, decimal_places=3, max_digits=10, null=True, validators=[django.core.validators.MinValueValidator(0)])),
|
|
('fat_100', models.DecimalField(blank=True, decimal_places=3, max_digits=10, null=True, validators=[django.core.validators.MinValueValidator(0)])),
|
|
('saturated_fat_100', models.DecimalField(blank=True, decimal_places=3, max_digits=10, null=True, validators=[django.core.validators.MinValueValidator(0)])),
|
|
('sugars_100', models.DecimalField(blank=True, decimal_places=3, max_digits=10, null=True, validators=[django.core.validators.MinValueValidator(0)])),
|
|
('fibre_100', models.DecimalField(blank=True, decimal_places=3, max_digits=10, null=True, validators=[django.core.validators.MinValueValidator(0)])),
|
|
('salt_100', models.DecimalField(blank=True, decimal_places=3, max_digits=10, null=True, validators=[django.core.validators.MinValueValidator(0)])),
|
|
('source', models.CharField(choices=[('openfoodfacts', 'Open Food Facts'), ('manual', 'Manual')], default='manual', max_length=16)),
|
|
('raw_data', models.JSONField(blank=True, default=dict)),
|
|
('fetched_at', models.DateTimeField(blank=True, null=True)),
|
|
('created_at', models.DateTimeField(auto_now_add=True)),
|
|
('updated_at', models.DateTimeField(auto_now=True)),
|
|
('owner', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='food_products', to=settings.AUTH_USER_MODEL)),
|
|
],
|
|
),
|
|
migrations.CreateModel(
|
|
name='FoodPortion',
|
|
fields=[
|
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
('label', models.CharField(max_length=100)),
|
|
('amount', models.DecimalField(decimal_places=3, max_digits=10, validators=[django.core.validators.MinValueValidator(0.001)])),
|
|
('unit', models.CharField(choices=[('g', 'g'), ('ml', 'ml')], max_length=2)),
|
|
('is_default', models.BooleanField(default=False)),
|
|
('created_at', models.DateTimeField(auto_now_add=True)),
|
|
('updated_at', models.DateTimeField(auto_now=True)),
|
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='food_portions', to=settings.AUTH_USER_MODEL)),
|
|
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='portions', to='food.foodproduct')),
|
|
],
|
|
),
|
|
migrations.CreateModel(
|
|
name='FoodLogEntry',
|
|
fields=[
|
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
('date', models.DateField(db_index=True)),
|
|
('time', models.TimeField(blank=True, null=True)),
|
|
('meal', models.CharField(choices=[('breakfast', 'Breakfast'), ('lunch', 'Lunch'), ('dinner', 'Dinner'), ('snacks', 'Snacks')], max_length=9)),
|
|
('product_name_snapshot', models.CharField(max_length=255)),
|
|
('brand_snapshot', models.CharField(blank=True, max_length=255)),
|
|
('barcode_snapshot', models.CharField(blank=True, max_length=64)),
|
|
('portion_label_snapshot', models.CharField(blank=True, max_length=100)),
|
|
('amount', models.DecimalField(decimal_places=3, max_digits=10, validators=[django.core.validators.MinValueValidator(0.001)])),
|
|
('unit', models.CharField(choices=[('g', 'g'), ('ml', 'ml')], max_length=2)),
|
|
('calories_kcal', models.DecimalField(blank=True, decimal_places=3, max_digits=10, null=True, validators=[django.core.validators.MinValueValidator(0)])),
|
|
('carbohydrates_g', models.DecimalField(blank=True, decimal_places=3, max_digits=10, null=True, validators=[django.core.validators.MinValueValidator(0)])),
|
|
('protein_g', models.DecimalField(blank=True, decimal_places=3, max_digits=10, null=True, validators=[django.core.validators.MinValueValidator(0)])),
|
|
('fat_g', models.DecimalField(blank=True, decimal_places=3, max_digits=10, null=True, validators=[django.core.validators.MinValueValidator(0)])),
|
|
('fibre_g', models.DecimalField(blank=True, decimal_places=3, max_digits=10, null=True, validators=[django.core.validators.MinValueValidator(0)])),
|
|
('sugars_g', models.DecimalField(blank=True, decimal_places=3, max_digits=10, null=True, validators=[django.core.validators.MinValueValidator(0)])),
|
|
('salt_g', models.DecimalField(blank=True, decimal_places=3, max_digits=10, null=True, validators=[django.core.validators.MinValueValidator(0)])),
|
|
('source', models.CharField(choices=[('openfoodfacts', 'Open Food Facts'), ('manual', 'Manual')], default='manual', max_length=16)),
|
|
('created_at', models.DateTimeField(auto_now_add=True)),
|
|
('updated_at', models.DateTimeField(auto_now=True)),
|
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='food_log_entries', to=settings.AUTH_USER_MODEL)),
|
|
('product', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='log_entries', to='food.foodproduct')),
|
|
],
|
|
options={
|
|
'ordering': ('date', 'time', 'pk'),
|
|
},
|
|
),
|
|
migrations.CreateModel(
|
|
name='FoodFavourite',
|
|
fields=[
|
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
('created_at', models.DateTimeField(auto_now_add=True)),
|
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='food_favourites', to=settings.AUTH_USER_MODEL)),
|
|
('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='favourites', to='food.foodproduct')),
|
|
],
|
|
),
|
|
migrations.AddConstraint(
|
|
model_name='foodproduct',
|
|
constraint=models.UniqueConstraint(condition=models.Q(('barcode', ''), _negated=True), fields=('owner', 'barcode'), name='food_unique_owner_barcode'),
|
|
),
|
|
migrations.AddConstraint(
|
|
model_name='foodportion',
|
|
constraint=models.UniqueConstraint(fields=('user', 'product', 'label'), name='food_unique_portion_label'),
|
|
),
|
|
migrations.AddConstraint(
|
|
model_name='foodfavourite',
|
|
constraint=models.UniqueConstraint(fields=('user', 'product'), name='food_unique_favourite'),
|
|
),
|
|
]
|