diff --git a/cookbook/helper/dal.py b/cookbook/helper/dal.py index 3b74b227..ab13f599 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 +from cookbook.models import Keyword, RecipeIngredient, Recipe, Unit, Ingredient class KeywordAutocomplete(autocomplete.Select2QuerySetView): @@ -19,12 +19,12 @@ class KeywordAutocomplete(autocomplete.Select2QuerySetView): class IngredientsAutocomplete(autocomplete.Select2QuerySetView): def get_queryset(self): if not self.request.user.is_authenticated: - return RecipeIngredient.objects.none() + return Ingredient.objects.none() - qs = RecipeIngredient.objects.all() + qs = Ingredient.objects.all() if self.q: - qs = qs.filter(name__istartswith=self.q) + qs = qs.filter(name__icontains=self.q) return qs diff --git a/cookbook/migrations/0024_auto_20200216_2313.py b/cookbook/migrations/0024_auto_20200216_2313.py new file mode 100644 index 00000000..bc3a9744 --- /dev/null +++ b/cookbook/migrations/0024_auto_20200216_2313.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.2 on 2020-02-16 22:13 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0023_auto_20200216_2311'), + ] + + operations = [ + migrations.RenameField( + model_name='recipeingredient', + old_name='name', + new_name='ingredient', + ), + ] diff --git a/cookbook/models.py b/cookbook/models.py index 83420cf1..db62a162 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -103,13 +103,13 @@ class Ingredient(models.Model): class RecipeIngredient(models.Model): - name = models.ForeignKey(Ingredient, on_delete=models.PROTECT, null=True) + ingredient = models.ForeignKey(Ingredient, on_delete=models.PROTECT, null=True) recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE) unit = models.ForeignKey(Unit, on_delete=models.PROTECT, null=True) amount = models.DecimalField(default=0, decimal_places=2, max_digits=16) def __str__(self): - return str(self.amount) + ' ' + str(self.unit) + ' ' + str(self.name) + return str(self.amount) + ' ' + str(self.unit) + ' ' + str(self.ingredient) class Comment(models.Model): diff --git a/cookbook/templates/forms/edit_internal_recipe.html b/cookbook/templates/forms/edit_internal_recipe.html index a88248f2..7df768b1 100644 --- a/cookbook/templates/forms/edit_internal_recipe.html +++ b/cookbook/templates/forms/edit_internal_recipe.html @@ -49,7 +49,15 @@