changed recipe ingredient relation
This commit is contained in:
parent
df912b8865
commit
bda38f0647
@ -51,7 +51,7 @@ admin.site.register(Food)
|
||||
|
||||
|
||||
class IngredientAdmin(admin.ModelAdmin):
|
||||
list_display = ('recipe', 'food', 'amount', 'unit')
|
||||
list_display = ('food', 'amount', 'unit')
|
||||
|
||||
|
||||
admin.site.register(Ingredient, IngredientAdmin)
|
||||
|
23
cookbook/migrations/0059_auto_20200625_2137.py
Normal file
23
cookbook/migrations/0059_auto_20200625_2137.py
Normal file
@ -0,0 +1,23 @@
|
||||
# Generated by Django 3.0.7 on 2020-06-25 19:37
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def migrate_ingredients(apps, schema_editor):
|
||||
Recipe = apps.get_model('cookbook', 'Recipe')
|
||||
Ingredient = apps.get_model('cookbook', 'Ingredient')
|
||||
|
||||
for r in Recipe.objects.all():
|
||||
for i in Ingredient.objects.filter(recipe=r).all():
|
||||
r.ingredients.add(i)
|
||||
r.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('cookbook', '0058_auto_20200625_2128'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(migrate_ingredients),
|
||||
]
|
23
cookbook/migrations/0060_auto_20200625_2144.py
Normal file
23
cookbook/migrations/0060_auto_20200625_2144.py
Normal file
@ -0,0 +1,23 @@
|
||||
# Generated by Django 3.0.7 on 2020-06-25 19:44
|
||||
|
||||
from django.db import migrations, models
|
||||
import uuid
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cookbook', '0059_auto_20200625_2137'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='ingredient',
|
||||
name='recipe',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='sharelink',
|
||||
name='uuid',
|
||||
field=models.UUIDField(default=uuid.UUID('a7a91b2e-ad33-4159-a35e-828a5244ede9')),
|
||||
),
|
||||
]
|
@ -165,7 +165,6 @@ class Food(models.Model):
|
||||
|
||||
|
||||
class Ingredient(models.Model):
|
||||
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE)
|
||||
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)
|
||||
|
@ -103,7 +103,7 @@
|
||||
{% endif %}
|
||||
|
||||
<div class="row">
|
||||
{% if ingredients %}
|
||||
{% if recipe.ingredients %}
|
||||
<div class="col-md-6 order-md-1 col-sm-12 order-sm-2 col-12 order-2">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
@ -124,7 +124,7 @@
|
||||
</div>
|
||||
<br/>
|
||||
<table class="table table-sm">
|
||||
{% for i in ingredients %}
|
||||
{% for i in recipe.ingredients.all %}
|
||||
{% if i.unit.name == 'Special:Header' %}
|
||||
<tr>
|
||||
<td style="padding-top: 8px!important; ">
|
||||
|
@ -79,7 +79,6 @@ 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 = Ingredient.objects.filter(recipe=recipe).all()
|
||||
comments = Comment.objects.filter(recipe=recipe)
|
||||
|
||||
if request.method == "POST":
|
||||
@ -116,7 +115,7 @@ def recipe_view(request, pk, share=None):
|
||||
ViewLog.objects.create(recipe=recipe, created_by=request.user)
|
||||
|
||||
return render(request, 'recipe_view.html',
|
||||
{'recipe': recipe, 'ingredients': ingredients, 'comments': comments, 'comment_form': comment_form,
|
||||
{'recipe': recipe, 'comments': comments, 'comment_form': comment_form,
|
||||
'bookmark_form': bookmark_form})
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user