diff --git a/reinheit/apps/brew/admin.py b/reinheit/apps/brew/admin.py index c13bcb7..12b168f 100644 --- a/reinheit/apps/brew/admin.py +++ b/reinheit/apps/brew/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin -from .models import Brew, YeastAddition, FermentableAddition, MaltAddition, ChemicalAddition +from .models import Brew, YeastAddition, FermentableAddition, MaltAddition, ChemicalAddition, HopAddition # Register your models here. @@ -15,6 +15,11 @@ class FermentableAdditionInline(admin.TabularInline): extra = 0 +class HopAdditionInline(admin.TabularInline): + model = HopAddition + extra = 0 + + class ChemicalAdditionInline(admin.TabularInline): model = ChemicalAddition extra = 0 @@ -25,11 +30,14 @@ class YeastAdditionInline(admin.TabularInline): extra = 0 + + @admin.register(Brew) class BrewAdmin(admin.ModelAdmin): inlines = [ MaltAdditionInline, FermentableAdditionInline, + HopAdditionInline, ChemicalAdditionInline, YeastAdditionInline, ] diff --git a/reinheit/apps/brew/migrations/0002_hopaddition.py b/reinheit/apps/brew/migrations/0002_hopaddition.py new file mode 100644 index 0000000..d580df1 --- /dev/null +++ b/reinheit/apps/brew/migrations/0002_hopaddition.py @@ -0,0 +1,47 @@ +# Generated by Django 5.0.6 on 2024-06-28 19:27 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("brew", "0001_initial"), + ("ingredients", "0003_rename_hops_hop"), + ] + + operations = [ + migrations.CreateModel( + name="HopAddition", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("mass", models.FloatField(help_text="The mass of ingredient added")), + ("added", models.DateTimeField(null=True)), + ( + "brew", + models.ForeignKey( + on_delete=django.db.models.deletion.CASCADE, to="brew.brew" + ), + ), + ( + "ingredient", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + to="ingredients.hop", + ), + ), + ], + options={ + "abstract": False, + }, + ), + ] diff --git a/reinheit/apps/brew/models.py b/reinheit/apps/brew/models.py index 556619c..77f4aee 100644 --- a/reinheit/apps/brew/models.py +++ b/reinheit/apps/brew/models.py @@ -69,3 +69,7 @@ class MaltAddition(AbstractAddition): class ChemicalAddition(AbstractAddition): ingredient = models.ForeignKey("ingredients.Chemical", on_delete=models.PROTECT) + + +class HopAddition(AbstractAddition): + ingredient = models.ForeignKey("ingredients.Hop", on_delete=models.PROTECT) diff --git a/reinheit/apps/ingredients/admin.py b/reinheit/apps/ingredients/admin.py index a42b37a..2df8d0a 100644 --- a/reinheit/apps/ingredients/admin.py +++ b/reinheit/apps/ingredients/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin -from .models import Producer, Yeast, Fermentable, Malt, Chemical +from .models import Producer, Yeast, Fermentable, Malt, Chemical, Hop # Register your models here. @@ -12,6 +12,12 @@ class IngredientAdmin(admin.ModelAdmin): search_fields = ["name", "producer__name"] +class HopAdmin(admin.ModelAdmin): + list_display = ["name", "kind", "alpha_acid"] + + search_fields = ["name"] + + @admin.register(Producer) class ProducerAdmin(admin.ModelAdmin): list_display = ["name"] @@ -21,3 +27,4 @@ admin.site.register(Yeast, IngredientAdmin) admin.site.register(Fermentable, IngredientAdmin) admin.site.register(Malt, IngredientAdmin) admin.site.register(Chemical, IngredientAdmin) +admin.site.register(Hop, HopAdmin) diff --git a/reinheit/apps/ingredients/migrations/0002_hops.py b/reinheit/apps/ingredients/migrations/0002_hops.py new file mode 100644 index 0000000..783f7cc --- /dev/null +++ b/reinheit/apps/ingredients/migrations/0002_hops.py @@ -0,0 +1,42 @@ +# Generated by Django 5.0.6 on 2024-06-28 19:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("ingredients", "0001_initial"), + ] + + operations = [ + migrations.CreateModel( + name="Hops", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("name", models.CharField(max_length=255)), + ( + "description", + models.CharField(blank=True, default="", max_length=255), + ), + ( + "kind", + models.CharField( + choices=[("PELL", "Pellets"), ("LEAF", "Leaf")], max_length=4 + ), + ), + ("alpha_acid", models.FloatField(help_text="Percentage of Alpha Acid")), + ], + options={ + "abstract": False, + }, + ), + ] diff --git a/reinheit/apps/ingredients/migrations/0003_rename_hops_hop.py b/reinheit/apps/ingredients/migrations/0003_rename_hops_hop.py new file mode 100644 index 0000000..a0715d4 --- /dev/null +++ b/reinheit/apps/ingredients/migrations/0003_rename_hops_hop.py @@ -0,0 +1,17 @@ +# Generated by Django 5.0.6 on 2024-06-28 19:27 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("ingredients", "0002_hops"), + ] + + operations = [ + migrations.RenameModel( + old_name="Hops", + new_name="Hop", + ), + ] diff --git a/reinheit/apps/ingredients/models.py b/reinheit/apps/ingredients/models.py index 37a7fc2..213ff17 100644 --- a/reinheit/apps/ingredients/models.py +++ b/reinheit/apps/ingredients/models.py @@ -53,3 +53,19 @@ class Fermentable(Ingredient): def __str__(self): return f"Other Fermentable: {self.name}" + + +class Hop(Ingredient): + class Type(models.TextChoices): + PELLET = "PELL", "Pellets" + LEAF = "LEAF", "Leaf" + + UNIT = "g" + + producer = None + + kind = models.CharField(max_length=4, choices=Type) + alpha_acid = models.FloatField(help_text="Percentage of Alpha Acid") + + def __str__(self): + return f"Hop: {self.name}"