diff --git a/.idea/recipes.iml b/.idea/recipes.iml index 7854b717..752aa83d 100644 --- a/.idea/recipes.iml +++ b/.idea/recipes.iml @@ -14,6 +14,7 @@ + @@ -28,7 +29,6 @@ diff --git a/cookbook/admin.py b/cookbook/admin.py index ea210c9b..718c53fb 100644 --- a/cookbook/admin.py +++ b/cookbook/admin.py @@ -47,7 +47,7 @@ class RecipeAdmin(admin.ModelAdmin): admin.site.register(Recipe, RecipeAdmin) admin.site.register(Unit) -admin.site.register(Ingredient) +admin.site.register(Food) class RecipeIngredientAdmin(admin.ModelAdmin): diff --git a/cookbook/filters.py b/cookbook/filters.py index 80662e67..f9743902 100644 --- a/cookbook/filters.py +++ b/cookbook/filters.py @@ -2,7 +2,7 @@ import django_filters from django.contrib.postgres.search import TrigramSimilarity from django.db.models import Q from cookbook.forms import MultiSelectWidget -from cookbook.models import Recipe, Keyword, Ingredient +from cookbook.models import Recipe, Keyword, Food from django.conf import settings from django.utils.translation import gettext as _ @@ -11,7 +11,7 @@ class RecipeFilter(django_filters.FilterSet): name = django_filters.CharFilter(method='filter_name') keywords = django_filters.ModelMultipleChoiceFilter(queryset=Keyword.objects.all(), widget=MultiSelectWidget, method='filter_keywords') - ingredients = django_filters.ModelMultipleChoiceFilter(queryset=Ingredient.objects.all(), widget=MultiSelectWidget, + ingredients = django_filters.ModelMultipleChoiceFilter(queryset=Food.objects.all(), widget=MultiSelectWidget, method='filter_ingredients', label=_('Ingredients')) @staticmethod @@ -50,5 +50,5 @@ class IngredientFilter(django_filters.FilterSet): name = django_filters.CharFilter(lookup_expr='icontains') class Meta: - model = Ingredient + model = Food fields = ['name'] diff --git a/cookbook/forms.py b/cookbook/forms.py index 338f2b90..632e8eb2 100644 --- a/cookbook/forms.py +++ b/cookbook/forms.py @@ -151,13 +151,13 @@ class IngredientMergeForm(forms.Form): prefix = 'ingredient' new_ingredient = forms.ModelChoiceField( - queryset=Ingredient.objects.all(), + queryset=Food.objects.all(), widget=SelectWidget, label=_('New Ingredient'), help_text=_('New ingredient that other gets replaced by.'), ) old_ingredient = forms.ModelChoiceField( - queryset=Ingredient.objects.all(), + queryset=Food.objects.all(), widget=SelectWidget, label=_('Old Ingredient'), help_text=_('Ingredient that should be replaced.'), @@ -186,9 +186,9 @@ class KeywordForm(forms.ModelForm): widgets = {'icon': EmojiPickerTextInput} -class IngredientForm(forms.ModelForm): +class FoodForm(forms.ModelForm): class Meta: - model = Ingredient + model = Food fields = ('name', 'recipe') widgets = {'recipe': SelectWidget} diff --git a/cookbook/helper/dal.py b/cookbook/helper/dal.py index ab13f599..3d5e85e6 100644 --- a/cookbook/helper/dal.py +++ b/cookbook/helper/dal.py @@ -1,6 +1,6 @@ from dal import autocomplete -from cookbook.models import Keyword, RecipeIngredient, Recipe, Unit, Ingredient +from cookbook.models import Keyword, Recipe, Unit, Food class KeywordAutocomplete(autocomplete.Select2QuerySetView): @@ -19,9 +19,9 @@ class KeywordAutocomplete(autocomplete.Select2QuerySetView): class IngredientsAutocomplete(autocomplete.Select2QuerySetView): def get_queryset(self): if not self.request.user.is_authenticated: - return Ingredient.objects.none() + return Food.objects.none() - qs = Ingredient.objects.all() + qs = Food.objects.all() if self.q: qs = qs.filter(name__icontains=self.q) diff --git a/cookbook/migrations/0056_auto_20200625_2118.py b/cookbook/migrations/0056_auto_20200625_2118.py new file mode 100644 index 00000000..b4615880 --- /dev/null +++ b/cookbook/migrations/0056_auto_20200625_2118.py @@ -0,0 +1,28 @@ +# Generated by Django 3.0.7 on 2020-06-25 19:18 + +from django.db import migrations, models +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0055_auto_20200616_1236'), + ] + + operations = [ + migrations.RenameModel( + old_name='Ingredient', + new_name='Food', + ), + migrations.AddField( + model_name='recipe', + name='ingredients', + field=models.ManyToManyField(blank=True, related_name='tmp_ingredients', to='cookbook.RecipeIngredient'), + ), + migrations.AlterField( + model_name='sharelink', + name='uuid', + field=models.UUIDField(default=uuid.UUID('a5f12617-9e4b-41e3-87ee-49db96090974')), + ), + ] diff --git a/cookbook/models.py b/cookbook/models.py index b557f23d..09d2cc6c 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -136,6 +136,7 @@ class Recipe(models.Model): link = models.CharField(max_length=512, null=True, blank=True) cors_link = models.CharField(max_length=1024, null=True, blank=True) keywords = models.ManyToManyField(Keyword, blank=True) + ingredients = models.ManyToManyField('RecipeIngredient', blank=True, related_name='tmp_ingredients') working_time = models.IntegerField(default=0) waiting_time = models.IntegerField(default=0) internal = models.BooleanField(default=False) @@ -155,7 +156,7 @@ class Unit(models.Model): return self.name -class Ingredient(models.Model): +class Food(models.Model): name = models.CharField(unique=True, max_length=128) recipe = models.ForeignKey(Recipe, null=True, blank=True, on_delete=models.SET_NULL) @@ -165,7 +166,7 @@ class Ingredient(models.Model): class RecipeIngredient(models.Model): recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE) - ingredient = models.ForeignKey(Ingredient, on_delete=models.PROTECT) + ingredient = models.ForeignKey(Food, on_delete=models.PROTECT) unit = models.ForeignKey(Unit, on_delete=models.PROTECT) amount = models.DecimalField(default=0, decimal_places=16, max_digits=32) note = models.CharField(max_length=64, null=True, blank=True) diff --git a/cookbook/serializer.py b/cookbook/serializer.py index f1dc7052..77f8266a 100644 --- a/cookbook/serializer.py +++ b/cookbook/serializer.py @@ -1,7 +1,7 @@ from django.contrib.auth.models import User from rest_framework import serializers -from cookbook.models import MealPlan, MealType, Recipe, ViewLog, UserPreference, Storage, Sync, SyncLog, Keyword, Ingredient, Unit, RecipeIngredient, Comment, RecipeImport, RecipeBook, RecipeBookEntry, ShareLink, CookLog +from cookbook.models import MealPlan, MealType, Recipe, ViewLog, UserPreference, Storage, Sync, SyncLog, Keyword, Unit, RecipeIngredient, Comment, RecipeImport, RecipeBook, RecipeBookEntry, ShareLink, CookLog, Food from cookbook.templatetags.custom_tags import markdown @@ -56,7 +56,7 @@ class UnitSerializer(serializers.ModelSerializer): class IngredientSerializer(serializers.ModelSerializer): class Meta: - model = Ingredient + model = Food fields = '__all__' diff --git a/cookbook/tables.py b/cookbook/tables.py index 1ee7b941..30c9c67c 100644 --- a/cookbook/tables.py +++ b/cookbook/tables.py @@ -48,7 +48,7 @@ class KeywordTable(tables.Table): class IngredientTable(tables.Table): - id = tables.LinkColumn('edit_ingredient', args=[A('id')]) + id = tables.LinkColumn('edit_food', args=[A('id')]) class Meta: model = Keyword diff --git a/cookbook/templates/base.html b/cookbook/templates/base.html index 297b73ad..ec5dd3c1 100644 --- a/cookbook/templates/base.html +++ b/cookbook/templates/base.html @@ -60,7 +60,7 @@ class="sr-only">(current) - -