créé un modèle fourniture et copie les données des ingrédients
This commit is contained in:
parent
00a8a28cfc
commit
aecf03141d
@ -32,6 +32,16 @@ class PainAdmin(admin.ModelAdmin):
|
|||||||
admin_site.register(models.Pain, PainAdmin)
|
admin_site.register(models.Pain, PainAdmin)
|
||||||
|
|
||||||
|
|
||||||
|
class FournitureAdmin(admin.ModelAdmin):
|
||||||
|
list_display = ["nom", "ordre", "couleur"]
|
||||||
|
list_editable = ["ordre", "couleur"]
|
||||||
|
actions = None
|
||||||
|
save_as = True
|
||||||
|
|
||||||
|
|
||||||
|
admin_site.register(models.Fourniture, FournitureAdmin)
|
||||||
|
|
||||||
|
|
||||||
class IngrédientInline(admin.TabularInline):
|
class IngrédientInline(admin.TabularInline):
|
||||||
model = models.Ingrédient
|
model = models.Ingrédient
|
||||||
sortable_field_name = "ordre"
|
sortable_field_name = "ordre"
|
||||||
|
@ -0,0 +1,55 @@
|
|||||||
|
# Generated by Django 4.2.13 on 2024-05-14 07:23
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
import colorfield.fields
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("core", "0007_ingrédient_couleur"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="Fourniture",
|
||||||
|
fields=[
|
||||||
|
(
|
||||||
|
"id",
|
||||||
|
models.AutoField(
|
||||||
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("nom", models.CharField(max_length=64)),
|
||||||
|
("ordre", models.SmallIntegerField(default=0)),
|
||||||
|
(
|
||||||
|
"couleur",
|
||||||
|
colorfield.fields.ColorField(
|
||||||
|
default="#000000", image_field=None, max_length=25, samples=None
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
"ordering": ["ordre"],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name="ingrédient",
|
||||||
|
options={"ordering": ["fourniture__ordre", "-quantité"]},
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="ingrédient",
|
||||||
|
name="fourniture",
|
||||||
|
field=models.ForeignKey(
|
||||||
|
blank=True,
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
null=True,
|
||||||
|
to="core.fourniture",
|
||||||
|
),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
39
fournée/core/migrations/0009_peuple_les_fournitures.py
Normal file
39
fournée/core/migrations/0009_peuple_les_fournitures.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
# Generated by Django 4.2.13 on 2024-05-14 07:24
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
def ingredients_vers_fournitures(apps, schema_editor):
|
||||||
|
Ingrédient = apps.get_model("core", "Ingrédient")
|
||||||
|
Fourniture = apps.get_model("core", "Fourniture")
|
||||||
|
for ingrédient in Ingrédient.objects.all():
|
||||||
|
fourniture, created = Fourniture.objects.get_or_create(
|
||||||
|
nom=ingrédient.nom,
|
||||||
|
defaults={
|
||||||
|
'ordre': ingrédient.ordre,
|
||||||
|
'couleur': ingrédient.couleur,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
ingrédient.fourniture = fourniture
|
||||||
|
ingrédient.save()
|
||||||
|
|
||||||
|
|
||||||
|
def fournitures_vers_ingredients(apps, schema_editor):
|
||||||
|
Ingrédient = apps.get_model("core", "Ingrédient")
|
||||||
|
Fourniture = apps.get_model("core", "Fourniture")
|
||||||
|
|
||||||
|
for fourniture in Fourniture.objects.all():
|
||||||
|
ingrédients = Ingrédient.objects.filter(fourniture=fourniture)
|
||||||
|
ingrédients.update(
|
||||||
|
nom=fourniture.nom,
|
||||||
|
ordre=fourniture.ordre,
|
||||||
|
couleur=fourniture.couleur,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("core", "0008_fourniture_alter_ingrédient_options_and_more"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [migrations.RunPython(ingredients_vers_fournitures, fournitures_vers_ingredients)]
|
@ -25,18 +25,32 @@ class Fournée(models.Model):
|
|||||||
for c in poids_qté
|
for c in poids_qté
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
class Fourniture(models.Model):
|
||||||
|
class Meta:
|
||||||
|
ordering = ["ordre"]
|
||||||
|
|
||||||
|
nom = models.CharField(max_length=64)
|
||||||
|
ordre = models.SmallIntegerField(default=0)
|
||||||
|
couleur = ColorField(default='#000000')
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.nom}"
|
||||||
|
|
||||||
|
|
||||||
class Ingrédient(models.Model):
|
class Ingrédient(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ["ordre", "-quantité"]
|
ordering = ["fourniture__ordre", "-quantité"]
|
||||||
|
|
||||||
recette = models.ForeignKey("Recette", on_delete=models.CASCADE)
|
recette = models.ForeignKey("Recette", on_delete=models.CASCADE)
|
||||||
nom = models.CharField(max_length=64)
|
nom = models.CharField(max_length=64)
|
||||||
|
fourniture = models.ForeignKey("Fourniture", on_delete=models.CASCADE, blank=True, null=True)
|
||||||
quantité = models.DecimalField(max_digits=6, decimal_places=3)
|
quantité = models.DecimalField(max_digits=6, decimal_places=3)
|
||||||
ordre = models.SmallIntegerField(default=0)
|
ordre = models.SmallIntegerField(default=0)
|
||||||
couleur = ColorField(default='#000000')
|
couleur = ColorField(default='#000000')
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.nom} ({self.quantité} kg)"
|
return f"{self.fourniture.nom} ({self.quantité} kg)"
|
||||||
|
|
||||||
|
|
||||||
class Recette(models.Model):
|
class Recette(models.Model):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user