Add ingredients and styles models
This commit is contained in:
parent
e0ecb769b1
commit
3b358774cf
22 changed files with 294 additions and 3 deletions
|
|
@ -38,6 +38,8 @@ INSTALLED_APPS = [
|
||||||
"django.contrib.messages",
|
"django.contrib.messages",
|
||||||
"django.contrib.staticfiles",
|
"django.contrib.staticfiles",
|
||||||
"reinheit.apps.brew",
|
"reinheit.apps.brew",
|
||||||
|
"reinheit.apps.styles",
|
||||||
|
"reinheit.apps.ingredients",
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
|
|
||||||
|
|
@ -5,5 +5,10 @@ from .models import Brew, Addition
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(Brew)
|
class AdditionInline(admin.TabularInline):
|
||||||
admin.site.register(Addition)
|
model = Addition
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(Brew)
|
||||||
|
class BrewAdmin(admin.ModelAdmin):
|
||||||
|
inlines = [AdditionInline]
|
||||||
|
|
|
||||||
77
reinheit/apps/brew/migrations/0001_initial.py
Normal file
77
reinheit/apps/brew/migrations/0001_initial.py
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
# Generated by Django 5.0.6 on 2024-06-24 20:32
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("ingredients", "0001_initial"),
|
||||||
|
("styles", "0001_initial"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="Brew",
|
||||||
|
fields=[
|
||||||
|
(
|
||||||
|
"id",
|
||||||
|
models.BigAutoField(
|
||||||
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("name", models.CharField(max_length=255)),
|
||||||
|
("pitch_date", models.DateField(null=True)),
|
||||||
|
("bottling_date", models.DateField(null=True)),
|
||||||
|
(
|
||||||
|
"fermenter_volume",
|
||||||
|
models.FloatField(
|
||||||
|
help_text="Volume of liquid in fermenter prior to piching yeast"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"bottled_volume",
|
||||||
|
models.FloatField(help_text="Volume of liquid bottled"),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"style",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.PROTECT, to="styles.style"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="Addition",
|
||||||
|
fields=[
|
||||||
|
(
|
||||||
|
"id",
|
||||||
|
models.BigAutoField(
|
||||||
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("mass", models.FloatField(help_text="The mass in kg added")),
|
||||||
|
("added", models.DateTimeField(null=True)),
|
||||||
|
(
|
||||||
|
"ingredient",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.PROTECT,
|
||||||
|
to="ingredients.ingredient",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"brew",
|
||||||
|
models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="brew.brew"),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -17,10 +17,16 @@ class Brew(models.Model):
|
||||||
)
|
)
|
||||||
bottled_volume = models.FloatField(help_text="Volume of liquid bottled")
|
bottled_volume = models.FloatField(help_text="Volume of liquid bottled")
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.style}: {self.name}"
|
||||||
|
|
||||||
|
|
||||||
class Addition(models.Model):
|
class Addition(models.Model):
|
||||||
ingredient = models.ForeignKey("ingredients.Ingredient", on_delte=models.PROTECT)
|
ingredient = models.ForeignKey("ingredients.Ingredient", on_delete=models.PROTECT)
|
||||||
brew = models.ForeignKey("Brew", on_delete=models.CASCADE)
|
brew = models.ForeignKey("Brew", on_delete=models.CASCADE)
|
||||||
|
|
||||||
mass = models.FloatField(help_text="The mass in kg added")
|
mass = models.FloatField(help_text="The mass in kg added")
|
||||||
added = models.DateTimeField(null=True)
|
added = models.DateTimeField(null=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.mass}kg of {self.ingredient} in {self.brew}"
|
||||||
|
|
|
||||||
0
reinheit/apps/ingredients/__init__.py
Normal file
0
reinheit/apps/ingredients/__init__.py
Normal file
8
reinheit/apps/ingredients/admin.py
Normal file
8
reinheit/apps/ingredients/admin.py
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
from .models import Ingredient, Producer
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
|
|
||||||
|
admin.site.register(Ingredient)
|
||||||
|
admin.site.register(Producer)
|
||||||
6
reinheit/apps/ingredients/apps.py
Normal file
6
reinheit/apps/ingredients/apps.py
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class IngredientsConfig(AppConfig):
|
||||||
|
default_auto_field = "django.db.models.BigAutoField"
|
||||||
|
name = "reinheit.apps.ingredients"
|
||||||
62
reinheit/apps/ingredients/migrations/0001_initial.py
Normal file
62
reinheit/apps/ingredients/migrations/0001_initial.py
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
# Generated by Django 5.0.6 on 2024-06-24 20:32
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = []
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="Producer",
|
||||||
|
fields=[
|
||||||
|
(
|
||||||
|
"id",
|
||||||
|
models.BigAutoField(
|
||||||
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("name", models.CharField(max_length=255)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="Ingredient",
|
||||||
|
fields=[
|
||||||
|
(
|
||||||
|
"id",
|
||||||
|
models.BigAutoField(
|
||||||
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"kind",
|
||||||
|
models.CharField(
|
||||||
|
choices=[
|
||||||
|
("YEAST", "Yeast"),
|
||||||
|
("FERM", "Fermentable"),
|
||||||
|
("HOP", "Hop"),
|
||||||
|
],
|
||||||
|
max_length=5,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("name", models.CharField(max_length=255)),
|
||||||
|
(
|
||||||
|
"producer",
|
||||||
|
models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE,
|
||||||
|
to="ingredients.producer",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Generated by Django 5.0.6 on 2024-06-24 20:37
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("ingredients", "0001_initial"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="ingredient",
|
||||||
|
name="description",
|
||||||
|
field=models.TextField(default=""),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 5.0.6 on 2024-06-24 20:37
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("ingredients", "0002_ingredient_description"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="ingredient",
|
||||||
|
name="description",
|
||||||
|
field=models.TextField(blank=True, default=""),
|
||||||
|
),
|
||||||
|
]
|
||||||
0
reinheit/apps/ingredients/migrations/__init__.py
Normal file
0
reinheit/apps/ingredients/migrations/__init__.py
Normal file
27
reinheit/apps/ingredients/models.py
Normal file
27
reinheit/apps/ingredients/models.py
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
|
|
||||||
|
|
||||||
|
class Ingredient(models.Model):
|
||||||
|
|
||||||
|
class Type(models.TextChoices):
|
||||||
|
YEAST = "YEAST", "Yeast"
|
||||||
|
FERMENTABLE = "FERM", "Fermentable"
|
||||||
|
HOP = "HOP", "Hop"
|
||||||
|
|
||||||
|
kind = models.CharField(max_length=5, choices=Type)
|
||||||
|
|
||||||
|
name = models.CharField(max_length=255)
|
||||||
|
description = models.TextField(blank=True, default="")
|
||||||
|
producer = models.ForeignKey("Producer", on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.get_kind_display()}: {self.name}"
|
||||||
|
|
||||||
|
|
||||||
|
class Producer(models.Model):
|
||||||
|
name = models.CharField(max_length=255)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
3
reinheit/apps/ingredients/tests.py
Normal file
3
reinheit/apps/ingredients/tests.py
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
3
reinheit/apps/ingredients/views.py
Normal file
3
reinheit/apps/ingredients/views.py
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
# Create your views here.
|
||||||
0
reinheit/apps/styles/__init__.py
Normal file
0
reinheit/apps/styles/__init__.py
Normal file
8
reinheit/apps/styles/admin.py
Normal file
8
reinheit/apps/styles/admin.py
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
from .models import Style
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
|
|
||||||
|
|
||||||
|
admin.site.register(Style)
|
||||||
6
reinheit/apps/styles/apps.py
Normal file
6
reinheit/apps/styles/apps.py
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class StylesConfig(AppConfig):
|
||||||
|
default_auto_field = "django.db.models.BigAutoField"
|
||||||
|
name = "reinheit.apps.styles"
|
||||||
28
reinheit/apps/styles/migrations/0001_initial.py
Normal file
28
reinheit/apps/styles/migrations/0001_initial.py
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
# Generated by Django 5.0.6 on 2024-06-24 20:32
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
initial = True
|
||||||
|
|
||||||
|
dependencies = []
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name="Style",
|
||||||
|
fields=[
|
||||||
|
(
|
||||||
|
"id",
|
||||||
|
models.BigAutoField(
|
||||||
|
auto_created=True,
|
||||||
|
primary_key=True,
|
||||||
|
serialize=False,
|
||||||
|
verbose_name="ID",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
("name", models.CharField(max_length=255)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
0
reinheit/apps/styles/migrations/__init__.py
Normal file
0
reinheit/apps/styles/migrations/__init__.py
Normal file
7
reinheit/apps/styles/models.py
Normal file
7
reinheit/apps/styles/models.py
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
|
|
||||||
|
|
||||||
|
class Style(models.Model):
|
||||||
|
name = models.CharField(max_length=255)
|
||||||
3
reinheit/apps/styles/tests.py
Normal file
3
reinheit/apps/styles/tests.py
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
3
reinheit/apps/styles/views.py
Normal file
3
reinheit/apps/styles/views.py
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
# Create your views here.
|
||||||
Loading…
Add table
Reference in a new issue