overview + center

This commit is contained in:
vabene1111
2018-02-01 00:20:47 +01:00
parent c382e9df24
commit 9bdc303f0e
9 changed files with 267 additions and 70 deletions

View File

@ -1,11 +1,14 @@
from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect
from django_tables2 import RequestConfig
from cookbook.forms import *
from cookbook.tables import RecipeTable
def index(request):
recipes = Recipe.objects.all()
return render(request, 'index.html', {'recipes': recipes})
table = RecipeTable(Recipe.objects.all())
RequestConfig(request, paginate={'per_page': 3}).configure(table)
return render(request, 'index.html', {'recipes': table})
@login_required
@ -16,6 +19,7 @@ def new_recipe(request):
recipe = form.save(commit=False)
recipe.created_by = request.user.id
recipe.save()
form.save_m2m()
return redirect('index')
else:
form = RecipeForm()