split protocol into steps
This commit is contained in:
parent
e04d691403
commit
a41542b478
5 changed files with 46 additions and 6 deletions
|
@ -1,14 +1,18 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from .models import Recipe, Ingredient, IngredientUsage
|
from .models import Recipe, Ingredient, IngredientUsage, Step
|
||||||
|
|
||||||
class IngredientUsageInline(admin.TabularInline):
|
class IngredientUsageInline(admin.TabularInline):
|
||||||
model = IngredientUsage
|
model = IngredientUsage
|
||||||
extra = 1
|
extra = 1
|
||||||
|
|
||||||
|
class StepInline(admin.TabularInline):
|
||||||
|
model = Step
|
||||||
|
extra = 1
|
||||||
|
|
||||||
class RecipeAdmin(admin.ModelAdmin):
|
class RecipeAdmin(admin.ModelAdmin):
|
||||||
inlines = (IngredientUsageInline,)
|
inlines = (IngredientUsageInline,StepInline)
|
||||||
fields = [ 'name', 'protocol' ]
|
fields = [ 'name' ]
|
||||||
|
|
||||||
admin.site.register(Recipe,RecipeAdmin)
|
admin.site.register(Recipe,RecipeAdmin)
|
||||||
admin.site.register(Ingredient)
|
admin.site.register(Ingredient)
|
||||||
|
|
27
recipes/migrations/0003_auto_20191107_1728.py
Normal file
27
recipes/migrations/0003_auto_20191107_1728.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
# Generated by Django 2.2.6 on 2019-11-07 16:28
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('recipes', '0002_recipe_protocol'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='recipe',
|
||||||
|
name='protocol',
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Step',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('step', models.PositiveSmallIntegerField()),
|
||||||
|
('protocol', models.TextField(default='')),
|
||||||
|
('recipe', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='recipes.Recipe')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
|
@ -9,11 +9,15 @@ class Ingredient(models.Model):
|
||||||
class Recipe(models.Model):
|
class Recipe(models.Model):
|
||||||
name = models.CharField(max_length=128)
|
name = models.CharField(max_length=128)
|
||||||
ingredients = models.ManyToManyField(Ingredient, through='IngredientUsage')
|
ingredients = models.ManyToManyField(Ingredient, through='IngredientUsage')
|
||||||
protocol = models.TextField(default='')
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
class Step(models.Model):
|
||||||
|
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE)
|
||||||
|
step = models.PositiveSmallIntegerField()
|
||||||
|
protocol = models.TextField(default='')
|
||||||
|
|
||||||
class IngredientUsage(models.Model):
|
class IngredientUsage(models.Model):
|
||||||
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE)
|
recipe = models.ForeignKey(Recipe, on_delete=models.CASCADE)
|
||||||
ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE)
|
ingredient = models.ForeignKey(Ingredient, on_delete=models.CASCADE)
|
||||||
|
|
|
@ -7,4 +7,8 @@
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<h2>Steps</h2>
|
<h2>Steps</h2>
|
||||||
<p>{{ recipe.protocol }}</p>
|
<ul>
|
||||||
|
{% for step in steps %}
|
||||||
|
<li>{{ step.protocol }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.views import generic
|
from django.views import generic
|
||||||
|
|
||||||
from .models import Recipe, IngredientUsage
|
from .models import Recipe, IngredientUsage, Step
|
||||||
|
|
||||||
|
|
||||||
class IndexView(generic.ListView):
|
class IndexView(generic.ListView):
|
||||||
|
@ -17,4 +17,5 @@ class DetailView(generic.DetailView):
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context['ingredient_list'] = IngredientUsage.objects.filter(recipe=self.object.pk)
|
context['ingredient_list'] = IngredientUsage.objects.filter(recipe=self.object.pk)
|
||||||
|
context['steps'] = Step.objects.filter(recipe=self.object.pk).order_by('step')
|
||||||
return context
|
return context
|
||||||
|
|
Loading…
Reference in a new issue