From 12fca700da47fda8c496b6d4eb090f7f547fef5c Mon Sep 17 00:00:00 2001 From: Chris Giacofei Date: Thu, 20 Jun 2024 15:02:17 -0400 Subject: [PATCH] Rename BatchRecipe -> Recipe. Much better now thanks. --- beer/admin.py | 6 +++--- .../0010_alter_batchrecipe_options.py | 17 +++++++++++++++++ .../0011_rename_batchrecipe_recipe.py | 17 +++++++++++++++++ beer/models.py | 12 ++++++------ beer/views.py | 8 ++++---- 5 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 beer/migrations/0010_alter_batchrecipe_options.py create mode 100644 beer/migrations/0011_rename_batchrecipe_recipe.py diff --git a/beer/admin.py b/beer/admin.py index 380e7f6..336255d 100644 --- a/beer/admin.py +++ b/beer/admin.py @@ -2,7 +2,7 @@ from django.contrib import admin from django.utils.html import format_html from django.apps import apps -from beer.models import Batch, BatchRecipe, Mash, MashStep, \ +from beer.models import Batch, Recipe, Mash, MashStep, \ RecipeFermentable, RecipeHop, RecipeMisc, RecipeYeast from yeast.models import Yeast @@ -34,8 +34,8 @@ class StrainInline(admin.TabularInline): extra = 1 -@admin.register(BatchRecipe) -class BatchRecipeAdmin(admin.ModelAdmin): +@admin.register(Recipe) +class RecipeAdmin(admin.ModelAdmin): list_display = ['name'] inlines = [ FermentableInline, diff --git a/beer/migrations/0010_alter_batchrecipe_options.py b/beer/migrations/0010_alter_batchrecipe_options.py new file mode 100644 index 0000000..e49f2be --- /dev/null +++ b/beer/migrations/0010_alter_batchrecipe_options.py @@ -0,0 +1,17 @@ +# Generated by Django 5.0.6 on 2024-06-20 18:33 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('beer', '0009_batchrecipe_equipment_and_more'), + ] + + operations = [ + migrations.AlterModelOptions( + name='batchrecipe', + options={'verbose_name': 'Recipe', 'verbose_name_plural': 'Recipes'}, + ), + ] diff --git a/beer/migrations/0011_rename_batchrecipe_recipe.py b/beer/migrations/0011_rename_batchrecipe_recipe.py new file mode 100644 index 0000000..4735f19 --- /dev/null +++ b/beer/migrations/0011_rename_batchrecipe_recipe.py @@ -0,0 +1,17 @@ +# Generated by Django 5.0.6 on 2024-06-20 18:59 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('beer', '0010_alter_batchrecipe_options'), + ] + + operations = [ + migrations.RenameModel( + old_name='BatchRecipe', + new_name='Recipe', + ), + ] diff --git a/beer/models.py b/beer/models.py index ad9ecfd..3be513a 100644 --- a/beer/models.py +++ b/beer/models.py @@ -33,7 +33,7 @@ class Batch(CustomModel): brewfather_num = models.IntegerField(default=1) brewfather_name = models.CharField(max_length=500, default='name') recipe = models.OneToOneField( - 'BatchRecipe', on_delete=models.CASCADE, default=1) + 'Recipe', on_delete=models.CASCADE, default=1) @property def brewfather_url(self): @@ -93,7 +93,7 @@ class CustomIngredient(CustomModel): abstract = True -class BatchRecipe(CustomModel): +class Recipe(CustomModel): """ Recipe to be stored with a batch.""" name = models.CharField(max_length=50) batch_recipe = models.BooleanField(null=True) @@ -282,7 +282,7 @@ class Fermentable(CustomIngredient): class RecipeFermentable(CustomModel): - recipe = models.ForeignKey(BatchRecipe, on_delete=models.CASCADE) + recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE) fermentable = models.ForeignKey(Fermentable, on_delete=models.CASCADE) quantity = models.DecimalField(max_digits=6, decimal_places=4) @@ -328,7 +328,7 @@ class RecipeHop(CustomModel): 4: 'Mash', 5: 'First Wort' } - recipe = models.ForeignKey(BatchRecipe, on_delete=models.CASCADE) + recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE) hop = models.ForeignKey(Hop, on_delete=models.CASCADE) quantity = models.DecimalField(max_digits=6, decimal_places=4) time = models.IntegerField(default=60, validators=[MinValueValidator(0)]) @@ -390,7 +390,7 @@ class Misc(CustomIngredient): class RecipeMisc(CustomModel): - recipe = models.ForeignKey(BatchRecipe, on_delete=models.CASCADE) + recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE) misc = models.ForeignKey(Misc, on_delete=models.CASCADE) quantity = models.DecimalField(max_digits=6, decimal_places=4) @@ -399,7 +399,7 @@ class RecipeMisc(CustomModel): class RecipeYeast(CustomModel): - recipe = models.ForeignKey(BatchRecipe, on_delete=models.CASCADE) + recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE) yeast = models.ForeignKey('yeast.Strain', on_delete=models.CASCADE) diff --git a/beer/views.py b/beer/views.py index 127ac59..e542e88 100644 --- a/beer/views.py +++ b/beer/views.py @@ -1,6 +1,6 @@ from django.shortcuts import render, get_object_or_404 -from .models import UserProfile, BatchRecipe, Batch +from .models import UserProfile, Recipe, Batch from .extras import get_batches import json @@ -20,7 +20,7 @@ def home(request): if Batch.objects.filter(brewfather_id=batch['_id']).first() is None: recipe_name = batch['recipe']['name'] - recipe_obj = BatchRecipe( + recipe_obj = Recipe( name=recipe_name, batch_recipe=True, recipe_json=json.dumps(batch['recipe']) ) @@ -36,13 +36,13 @@ def home(request): batch_obj.save() context = { - 'recipes': BatchRecipe.objects.all(), + 'recipes': Recipe.objects.all(), } return render(request, 'beer/home.html', context) def view_recipe(request, recipe_id): - recipe = get_object_or_404(BatchRecipe, pk=recipe_id) + recipe = get_object_or_404(Recipe, pk=recipe_id) context = { 'recipe': recipe,