Add MCP nutrition ingredient import and classification
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
# Generated by Django 6.1.1 on 2026-11-02 10:10
|
||||
|
||||
import django.db.models.deletion
|
||||
import uuid
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('food', '0016_inventoryscanrun_food_one_active_scan_run'),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='CanonicalIngredient',
|
||||
fields=[
|
||||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
||||
('name', models.CharField(max_length=180)),
|
||||
('normalized_name', models.CharField(max_length=180)),
|
||||
('category', models.CharField(max_length=40)),
|
||||
('subcategory', models.CharField(blank=True, max_length=80)),
|
||||
('form', models.CharField(blank=True, max_length=80)),
|
||||
('preparation', models.CharField(default='unknown', max_length=20)),
|
||||
('aliases', models.JSONField(default=list)),
|
||||
('attributes', models.JSONField(default=dict)),
|
||||
('confidence', models.DecimalField(decimal_places=3, max_digits=4)),
|
||||
('provenance', models.CharField(default='source_inference', max_length=40)),
|
||||
('classification_version', models.PositiveIntegerField(default=1)),
|
||||
('verified', models.BooleanField(default=False)),
|
||||
('created_at', models.DateTimeField(auto_now_add=True)),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='NutritionSource',
|
||||
fields=[
|
||||
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
||||
('programme', models.CharField(max_length=80)),
|
||||
('document_name', models.CharField(max_length=255)),
|
||||
('sha256', models.CharField(max_length=64)),
|
||||
('week_start', models.DateField(blank=True, null=True)),
|
||||
('week_end', models.DateField(blank=True, null=True)),
|
||||
('payload_hash', models.CharField(max_length=64)),
|
||||
('idempotency_key', models.CharField(max_length=128)),
|
||||
('imported_at', models.DateTimeField(auto_now_add=True)),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='SuggestedIngredient',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('row_key', models.CharField(max_length=100)),
|
||||
('original_label', models.CharField(max_length=255)),
|
||||
('quantity', models.DecimalField(decimal_places=3, max_digits=10)),
|
||||
('unit', models.CharField(max_length=20)),
|
||||
('preparation', models.CharField(max_length=20)),
|
||||
('page', models.PositiveIntegerField()),
|
||||
('nutrition', models.JSONField(default=dict)),
|
||||
('uncertainty', models.JSONField(default=list)),
|
||||
('canonical', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='suggestions', to='food.canonicalingredient')),
|
||||
('source', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ingredients', to='food.nutritionsource')),
|
||||
],
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='canonicalingredient',
|
||||
constraint=models.UniqueConstraint(fields=('user', 'normalized_name', 'form', 'preparation'), name='food_unique_canonical_identity'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='nutritionsource',
|
||||
constraint=models.UniqueConstraint(fields=('user', 'sha256'), name='food_unique_nutrition_document'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='nutritionsource',
|
||||
constraint=models.UniqueConstraint(fields=('user', 'idempotency_key'), name='food_unique_nutrition_key'),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name='suggestedingredient',
|
||||
constraint=models.UniqueConstraint(fields=('source', 'row_key'), name='food_unique_nutrition_row'),
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user