68 lines
3.6 KiB
Python
68 lines
3.6 KiB
Python
# Generated by Django 6.1.2 on 2026-10-21 18:45
|
|
|
|
import django.core.validators
|
|
import django.db.models.deletion
|
|
import uuid
|
|
from decimal import Decimal
|
|
from django.conf import settings
|
|
from django.db import migrations, models
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
initial = True
|
|
|
|
dependencies = [
|
|
('food', '0011_log_quantity'),
|
|
('recipes', '0006_cooklater'),
|
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
|
]
|
|
|
|
operations = [
|
|
migrations.CreateModel(
|
|
name='GroceryItem',
|
|
fields=[
|
|
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
|
|
('name', models.CharField(max_length=180)),
|
|
('quantity', models.DecimalField(decimal_places=3, max_digits=10, validators=[django.core.validators.MinValueValidator(Decimal('0.001'))])),
|
|
('unit', models.CharField(choices=[('pieces', 'pieces'), ('g', 'g'), ('kg', 'kg'), ('ml', 'ml'), ('L', 'L'), ('packs', 'packs'), ('portions', 'portions'), ('tsp', 'tsp'), ('tbsp', 'tbsp')], max_length=10)),
|
|
('category', models.CharField(blank=True, max_length=80)),
|
|
('notes', models.TextField(blank=True)),
|
|
('status', models.CharField(choices=[('needed', 'Needed'), ('purchased', 'Purchased')], default='needed', max_length=12)),
|
|
('purchased_at', models.DateTimeField(blank=True, null=True)),
|
|
('idempotency_key', models.CharField(blank=True, max_length=100)),
|
|
('created_at', models.DateTimeField(auto_now_add=True)),
|
|
('updated_at', models.DateTimeField(auto_now=True)),
|
|
('product', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='food.foodproduct')),
|
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='grocery_items', to=settings.AUTH_USER_MODEL)),
|
|
],
|
|
options={
|
|
'ordering': ('status', 'category', 'name', 'created_at'),
|
|
},
|
|
),
|
|
migrations.CreateModel(
|
|
name='GrocerySource',
|
|
fields=[
|
|
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
|
('requested_quantity', models.DecimalField(decimal_places=3, max_digits=10)),
|
|
('requested_unit', models.CharField(max_length=10)),
|
|
('selection_key', models.CharField(max_length=120)),
|
|
('ingredient', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='recipes.recipeingredient')),
|
|
('item', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='sources', to='groceries.groceryitem')),
|
|
('recipe', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='recipes.recipe')),
|
|
],
|
|
),
|
|
migrations.AddConstraint(
|
|
model_name='groceryitem',
|
|
constraint=models.CheckConstraint(condition=models.Q(('quantity__gt', 0)), name='groceries_positive_quantity'),
|
|
),
|
|
migrations.AddConstraint(
|
|
model_name='groceryitem',
|
|
constraint=models.UniqueConstraint(condition=models.Q(('idempotency_key', ''), _negated=True), fields=('user', 'idempotency_key'), name='groceries_unique_idempotency_key'),
|
|
),
|
|
migrations.AddConstraint(
|
|
model_name='grocerysource',
|
|
constraint=models.UniqueConstraint(fields=('item', 'recipe', 'ingredient', 'selection_key'), name='groceries_unique_source'),
|
|
),
|
|
]
|