diff --git a/cookbook/admin.py b/cookbook/admin.py
index 718c53fb..97103c5c 100644
--- a/cookbook/admin.py
+++ b/cookbook/admin.py
@@ -50,11 +50,11 @@ admin.site.register(Unit)
admin.site.register(Food)
-class RecipeIngredientAdmin(admin.ModelAdmin):
- list_display = ('recipe', 'ingredient', 'amount', 'unit')
+class IngredientAdmin(admin.ModelAdmin):
+ list_display = ('recipe', 'food', 'amount', 'unit')
-admin.site.register(RecipeIngredient, RecipeIngredientAdmin)
+admin.site.register(Ingredient, IngredientAdmin)
class CommentAdmin(admin.ModelAdmin):
diff --git a/cookbook/filters.py b/cookbook/filters.py
index f9743902..54367605 100644
--- a/cookbook/filters.py
+++ b/cookbook/filters.py
@@ -27,7 +27,7 @@ class RecipeFilter(django_filters.FilterSet):
if not name == 'ingredients':
return queryset
for x in value:
- queryset = queryset.filter(recipeingredient__ingredient=x).distinct()
+ queryset = queryset.filter(ingredient__food=x).distinct()
return queryset
@staticmethod
diff --git a/cookbook/migrations/0057_auto_20200625_2127.py b/cookbook/migrations/0057_auto_20200625_2127.py
new file mode 100644
index 00000000..a6f3daa2
--- /dev/null
+++ b/cookbook/migrations/0057_auto_20200625_2127.py
@@ -0,0 +1,24 @@
+# Generated by Django 3.0.7 on 2020-06-25 19:27
+
+from django.db import migrations, models
+import uuid
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('cookbook', '0056_auto_20200625_2118'),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name='recipeingredient',
+ old_name='ingredient',
+ new_name='food',
+ ),
+ migrations.AlterField(
+ model_name='sharelink',
+ name='uuid',
+ field=models.UUIDField(default=uuid.UUID('4a604ec8-c158-4011-ab5d-ddad7604c1e3')),
+ ),
+ ]
diff --git a/cookbook/migrations/0058_auto_20200625_2128.py b/cookbook/migrations/0058_auto_20200625_2128.py
new file mode 100644
index 00000000..29068723
--- /dev/null
+++ b/cookbook/migrations/0058_auto_20200625_2128.py
@@ -0,0 +1,23 @@
+# Generated by Django 3.0.7 on 2020-06-25 19:28
+
+from django.db import migrations, models
+import uuid
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('cookbook', '0057_auto_20200625_2127'),
+ ]
+
+ operations = [
+ migrations.RenameModel(
+ old_name='RecipeIngredient',
+ new_name='Ingredient',
+ ),
+ migrations.AlterField(
+ model_name='sharelink',
+ name='uuid',
+ field=models.UUIDField(default=uuid.UUID('27328011-54fb-46fa-8846-424d5828d858')),
+ ),
+ ]
diff --git a/cookbook/models.py b/cookbook/models.py
index 09d2cc6c..09c75427 100644
--- a/cookbook/models.py
+++ b/cookbook/models.py
@@ -136,7 +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')
+ ingredients = models.ManyToManyField('Ingredient', blank=True, related_name='tmp_ingredients')
working_time = models.IntegerField(default=0)
waiting_time = models.IntegerField(default=0)
internal = models.BooleanField(default=False)
@@ -164,15 +164,15 @@ class Food(models.Model):
return self.name
-class RecipeIngredient(models.Model):
+class Ingredient(models.Model):
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE)
- ingredient = models.ForeignKey(Food, on_delete=models.PROTECT)
+ food = 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)
def __str__(self):
- return str(self.amount) + ' ' + str(self.unit) + ' ' + str(self.ingredient)
+ return str(self.amount) + ' ' + str(self.unit) + ' ' + str(self.food)
class Comment(models.Model):
diff --git a/cookbook/serializer.py b/cookbook/serializer.py
index 77f8266a..a3a4c56a 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, Unit, RecipeIngredient, Comment, RecipeImport, RecipeBook, RecipeBookEntry, ShareLink, CookLog, Food
+from cookbook.models import MealPlan, MealType, Recipe, ViewLog, UserPreference, Storage, Sync, SyncLog, Keyword, Unit, Ingredient, Comment, RecipeImport, RecipeBook, RecipeBookEntry, ShareLink, CookLog, Food
from cookbook.templatetags.custom_tags import markdown
@@ -54,15 +54,15 @@ class UnitSerializer(serializers.ModelSerializer):
fields = '__all__'
-class IngredientSerializer(serializers.ModelSerializer):
+class FoodSerializer(serializers.ModelSerializer):
class Meta:
model = Food
fields = '__all__'
-class RecipeIngredientSerializer(serializers.ModelSerializer):
+class IngredientSerializer(serializers.ModelSerializer):
class Meta:
- model = RecipeIngredient
+ model = Ingredient
fields = '__all__'
diff --git a/cookbook/templates/recipe_view.html b/cookbook/templates/recipe_view.html
index f9c4f205..76661c12 100644
--- a/cookbook/templates/recipe_view.html
+++ b/cookbook/templates/recipe_view.html
@@ -154,12 +154,12 @@
- {% if i.ingredient.recipe %}
-
{% endif %}
- {{ i.ingredient.name }}
- {% if i.ingredient.recipe %}
+ {{ i.food.name }}
+ {% if i.food.recipe %}
{% endif %}
diff --git a/cookbook/tests/edits/test_edits_recipe.py b/cookbook/tests/edits/test_edits_recipe.py
index 6a5a8cee..31494b93 100644
--- a/cookbook/tests/edits/test_edits_recipe.py
+++ b/cookbook/tests/edits/test_edits_recipe.py
@@ -1,7 +1,7 @@
from django.contrib import auth
from django.urls import reverse
-from cookbook.models import Recipe, RecipeIngredient, Unit, Storage, Food
+from cookbook.models import Recipe, Ingredient, Unit, Storage, Food
from cookbook.tests.views.test_views import TestViews
@@ -83,7 +83,7 @@ class TestEditsRecipe(TestViews):
{'name': 'Changed', 'working_time': 15, 'waiting_time': 15,
'ingredients': '[{"ingredient__name":"Tomato","unit__name":"g","amount":100,"delete":false},{"ingredient__name":"Egg","unit__name":"Piece","amount":"2,5","delete":false}]'})
self.assertEqual(r.status_code, 200)
- self.assertEqual(2, RecipeIngredient.objects.filter(recipe=recipe).count())
+ self.assertEqual(2, Ingredient.objects.filter(recipe=recipe).count())
r = self.user_client_1.post(url,
{'name': "Test", 'working_time': "Test", 'waiting_time': 15,
diff --git a/cookbook/urls.py b/cookbook/urls.py
index 49f0326d..5ff1052a 100644
--- a/cookbook/urls.py
+++ b/cookbook/urls.py
@@ -11,8 +11,8 @@ from cookbook.helper import dal
router = routers.DefaultRouter()
router.register(r'user-preference', api.UserPreferenceViewSet)
router.register(r'recipe', api.RecipeViewSet)
-router.register(r'ingredient', api.IngredientViewSet)
-router.register(r'recipe-ingredient', api.RecipeIngredientViewSet)
+router.register(r'food', api.FoodViewSet)
+router.register(r'recipe-ingredient', api.IngredientViewSet)
router.register(r'meal-plan', api.MealPlanViewSet)
router.register(r'meal-type', api.MealTypeViewSet)
router.register(r'view-log', api.ViewLogViewSet)
diff --git a/cookbook/views/api.py b/cookbook/views/api.py
index 5e056f9f..82563688 100644
--- a/cookbook/views/api.py
+++ b/cookbook/views/api.py
@@ -18,10 +18,10 @@ from rest_framework.mixins import RetrieveModelMixin, UpdateModelMixin, ListMode
from cookbook.helper.permission_helper import group_required, CustomIsOwner, CustomIsAdmin, CustomIsUser
from cookbook.helper.recipe_url_import import get_from_html
-from cookbook.models import Recipe, Sync, Storage, CookLog, MealPlan, MealType, ViewLog, UserPreference, RecipeBook, RecipeIngredient, Food
+from cookbook.models import Recipe, Sync, Storage, CookLog, MealPlan, MealType, ViewLog, UserPreference, RecipeBook, Ingredient, Food
from cookbook.provider.dropbox import Dropbox
from cookbook.provider.nextcloud import Nextcloud
-from cookbook.serializer import MealPlanSerializer, MealTypeSerializer, RecipeSerializer, ViewLogSerializer, UserNameSerializer, UserPreferenceSerializer, RecipeBookSerializer, RecipeIngredientSerializer, IngredientSerializer
+from cookbook.serializer import MealPlanSerializer, MealTypeSerializer, RecipeSerializer, ViewLogSerializer, UserNameSerializer, UserPreferenceSerializer, RecipeBookSerializer, IngredientSerializer, FoodSerializer
class UserNameViewSet(viewsets.ModelViewSet):
@@ -134,15 +134,15 @@ class RecipeViewSet(viewsets.ModelViewSet):
return queryset
-class RecipeIngredientViewSet(viewsets.ModelViewSet):
- queryset = RecipeIngredient.objects.all()
- serializer_class = RecipeIngredientSerializer
+class IngredientViewSet(viewsets.ModelViewSet):
+ queryset = Ingredient.objects.all()
+ serializer_class = IngredientSerializer
permission_classes = [CustomIsUser]
-class IngredientViewSet(viewsets.ModelViewSet):
+class FoodViewSet(viewsets.ModelViewSet):
queryset = Food.objects.all()
- serializer_class = IngredientSerializer
+ serializer_class = FoodSerializer
permission_classes = [CustomIsUser]
diff --git a/cookbook/views/data.py b/cookbook/views/data.py
index caef102d..15e0f7a6 100644
--- a/cookbook/views/data.py
+++ b/cookbook/views/data.py
@@ -128,7 +128,7 @@ def import_url(request):
# TODO return proper error
pass
- RecipeIngredient.objects.create(recipe=recipe, ingredient=i, unit=u, amount=ing['amount'])
+ Ingredient.objects.create(recipe=recipe, ingredient=i, unit=u, amount=ing['amount'])
if data['image'] != '':
response = requests.get(data['image'])
diff --git a/cookbook/views/edit.py b/cookbook/views/edit.py
index e837ad3b..257d2353 100644
--- a/cookbook/views/edit.py
+++ b/cookbook/views/edit.py
@@ -19,7 +19,7 @@ from cookbook.forms import ExternalRecipeForm, KeywordForm, StorageForm, SyncFor
from cookbook.helper.permission_helper import group_required, GroupRequiredMixin
from cookbook.helper.permission_helper import OwnerRequiredMixin
-from cookbook.models import Recipe, Sync, Keyword, RecipeImport, Storage, Comment, RecipeIngredient, RecipeBook, \
+from cookbook.models import Recipe, Sync, Keyword, RecipeImport, Storage, Comment, Ingredient, RecipeBook, \
MealPlan, Unit, Food
from cookbook.provider.dropbox import Dropbox
from cookbook.provider.nextcloud import Nextcloud
@@ -83,10 +83,10 @@ def internal_recipe_update(request, pk):
except simplejson.errors.JSONDecodeError:
form_ingredients = []
- RecipeIngredient.objects.filter(recipe=recipe_instance).delete()
+ Ingredient.objects.filter(recipe=recipe_instance).delete()
for i in form_ingredients:
- recipe_ingredient = RecipeIngredient()
+ recipe_ingredient = Ingredient()
recipe_ingredient.recipe = recipe_instance
if 'note' in i:
@@ -95,10 +95,10 @@ def internal_recipe_update(request, pk):
if Food.objects.filter(name=i['ingredient__name']).exists():
recipe_ingredient.ingredient = Food.objects.get(name=i['ingredient__name'])
else:
- ingredient = Food()
- ingredient.name = i['ingredient__name']
- ingredient.save()
- recipe_ingredient.ingredient = ingredient
+ food = Food()
+ food.name = i['food__name']
+ food.save()
+ recipe_ingredient.ingredient = food
if isinstance(i['amount'], str):
try:
@@ -127,7 +127,7 @@ def internal_recipe_update(request, pk):
else:
form = InternalRecipeForm(instance=recipe_instance)
- ingredients = RecipeIngredient.objects.select_related('unit__name', 'ingredient__name').filter(recipe=recipe_instance).values('ingredient__name', 'unit__name', 'amount', 'note').order_by('id')
+ ingredients = Ingredient.objects.select_related('unit__name', 'food__name').filter(recipe=recipe_instance).values('food__name', 'unit__name', 'amount', 'note').order_by('id')
return render(request, 'forms/edit_internal_recipe.html',
{'form': form, 'ingredients': json.dumps(list(ingredients)),
@@ -181,7 +181,7 @@ class FoodUpdate(GroupRequiredMixin, UpdateView):
def get_context_data(self, **kwargs):
context = super(FoodUpdate, self).get_context_data(**kwargs)
- context['title'] = _("Ingredient")
+ context['title'] = _("Food")
return context
@@ -325,7 +325,7 @@ def edit_ingredients(request):
if units_form.is_valid():
new_unit = units_form.cleaned_data['new_unit']
old_unit = units_form.cleaned_data['old_unit']
- recipe_ingredients = RecipeIngredient.objects.filter(unit=old_unit).all()
+ recipe_ingredients = Ingredient.objects.filter(unit=old_unit).all()
for i in recipe_ingredients:
i.unit = new_unit
i.save()
@@ -338,7 +338,7 @@ def edit_ingredients(request):
if ingredients_form.is_valid():
new_ingredient = ingredients_form.cleaned_data['new_food']
old_ingredient = ingredients_form.cleaned_data['old_food']
- recipe_ingredients = RecipeIngredient.objects.filter(ingredient=old_ingredient).all()
+ recipe_ingredients = Ingredient.objects.filter(food=old_ingredient).all()
for i in recipe_ingredients:
i.ingredient = new_ingredient
i.save()
diff --git a/cookbook/views/import_export.py b/cookbook/views/import_export.py
index 352d2819..9bd8648d 100644
--- a/cookbook/views/import_export.py
+++ b/cookbook/views/import_export.py
@@ -12,7 +12,7 @@ from django.urls import reverse_lazy
from django.utils.translation import gettext as _
from cookbook.forms import ExportForm, ImportForm
from cookbook.helper.permission_helper import group_required
-from cookbook.models import RecipeIngredient, Recipe, Unit, Food, Keyword, Food
+from cookbook.models import Ingredient, Recipe, Unit, Food, Keyword, Food
@group_required('user')
@@ -47,8 +47,8 @@ def import_recipe(request):
pass
for ri in data['recipe_ingredients']:
- RecipeIngredient.objects.create(recipe=recipe, ingredient=Food.objects.get(name=ri['ingredient']),
- unit=Unit.objects.get(name=ri['unit']), amount=ri['amount'], note=ri['note'])
+ Ingredient.objects.create(recipe=recipe, ingredient=Food.objects.get(name=ri['food']),
+ unit=Unit.objects.get(name=ri['unit']), amount=ri['amount'], note=ri['note'])
if data['image']:
fmt, img = data['image'].split(';base64,')
@@ -84,13 +84,13 @@ def export_recipe(request):
for k in recipe.keywords.all():
export['keywords'].append({'name': k.name, 'icon': k.icon, 'description': k.description})
- for ri in RecipeIngredient.objects.filter(recipe=recipe).all():
+ for ri in Ingredient.objects.filter(recipe=recipe).all():
if ri.unit not in export['units']:
export['units'].append({'name': ri.unit.name, 'description': ri.unit.description})
if ri.ingredient not in export['ingredients']:
export['ingredients'].append({'name': ri.ingredient.name})
- export['recipe_ingredients'].append({'ingredient': ri.ingredient.name, 'unit': ri.unit.name, 'amount': float(ri.amount), 'note': ri.note})
+ export['recipe_ingredients'].append({'food': ri.ingredient.name, 'unit': ri.unit.name, 'amount': float(ri.amount), 'note': ri.note})
if recipe.image and form.cleaned_data['image']:
with open(recipe.image.path, 'rb') as img_f:
diff --git a/cookbook/views/views.py b/cookbook/views/views.py
index 5c9a34d3..633bdb57 100644
--- a/cookbook/views/views.py
+++ b/cookbook/views/views.py
@@ -79,7 +79,7 @@ def recipe_view(request, pk, share=None):
messages.add_message(request, messages.ERROR, _('You do not have the required permissions to view this page!'))
return HttpResponseRedirect(reverse('index'))
- ingredients = RecipeIngredient.objects.filter(recipe=recipe).all()
+ ingredients = Ingredient.objects.filter(recipe=recipe).all()
comments = Comment.objects.filter(recipe=recipe)
if request.method == "POST":
|