Add MCP nutrition ingredient import and classification
This commit is contained in:
@@ -180,6 +180,59 @@ class InventoryCategory(models.Model):
|
||||
return self.name
|
||||
|
||||
|
||||
class CanonicalIngredient(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
||||
name = models.CharField(max_length=180)
|
||||
normalized_name = models.CharField(max_length=180)
|
||||
category = models.CharField(max_length=40)
|
||||
subcategory = models.CharField(max_length=80, blank=True)
|
||||
form = models.CharField(max_length=80, blank=True)
|
||||
preparation = models.CharField(max_length=20, default='unknown')
|
||||
aliases = models.JSONField(default=list)
|
||||
attributes = models.JSONField(default=dict)
|
||||
confidence = models.DecimalField(max_digits=4, decimal_places=3)
|
||||
provenance = models.CharField(max_length=40, default='source_inference')
|
||||
classification_version = models.PositiveIntegerField(default=1)
|
||||
verified = models.BooleanField(default=False)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
constraints = [models.UniqueConstraint(fields=('user', 'normalized_name', 'form', 'preparation'), name='food_unique_canonical_identity')]
|
||||
|
||||
|
||||
class NutritionSource(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
||||
programme = models.CharField(max_length=80)
|
||||
document_name = models.CharField(max_length=255)
|
||||
sha256 = models.CharField(max_length=64)
|
||||
week_start = models.DateField(null=True, blank=True)
|
||||
week_end = models.DateField(null=True, blank=True)
|
||||
payload_hash = models.CharField(max_length=64)
|
||||
idempotency_key = models.CharField(max_length=128)
|
||||
imported_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
constraints = [models.UniqueConstraint(fields=('user', 'sha256'), name='food_unique_nutrition_document'), models.UniqueConstraint(fields=('user', 'idempotency_key'), name='food_unique_nutrition_key')]
|
||||
|
||||
|
||||
class SuggestedIngredient(models.Model):
|
||||
source = models.ForeignKey(NutritionSource, on_delete=models.CASCADE, related_name='ingredients')
|
||||
canonical = models.ForeignKey(CanonicalIngredient, on_delete=models.PROTECT, related_name='suggestions')
|
||||
row_key = models.CharField(max_length=100)
|
||||
original_label = models.CharField(max_length=255)
|
||||
quantity = models.DecimalField(max_digits=10, decimal_places=3)
|
||||
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)
|
||||
|
||||
class Meta:
|
||||
constraints = [models.UniqueConstraint(fields=('source', 'row_key'), name='food_unique_nutrition_row')]
|
||||
|
||||
|
||||
class KitchenInventoryItem(models.Model):
|
||||
api_id = models.UUIDField(default=uuid.uuid4, unique=True, editable=False)
|
||||
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='kitchen_inventory')
|
||||
|
||||
Reference in New Issue
Block a user