This commit is contained in:
Maximilian Friedersdorff 2024-06-28 20:29:32 +01:00
parent 2a8a0febe1
commit cff2e4a55d
7 changed files with 143 additions and 2 deletions

View file

@ -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,
]

View file

@ -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,
},
),
]

View file

@ -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)

View file

@ -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)

View file

@ -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,
},
),
]

View file

@ -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",
),
]

View file

@ -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}"