diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 3d4fa4013..9ea723ede 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,16 +2,12 @@ - - - - - - + - + + @@ -151,23 +104,23 @@ @@ -257,7 +210,7 @@ - + @@ -324,10 +277,10 @@ - + - + @@ -353,6 +306,13 @@ + + + + + + @@ -402,9 +362,7 @@ - - - + @@ -469,7 +427,7 @@ - + @@ -536,16 +494,6 @@ - - - - - - - - - - @@ -592,16 +540,6 @@ - - - - - - - - - - @@ -626,24 +564,6 @@ - - - - - - - - - - - - - - - - - - @@ -654,37 +574,75 @@ - - - - - - - - - - + + - - + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cookbook/tables.py b/cookbook/tables.py index c06a854d7..7d28904c7 100644 --- a/cookbook/tables.py +++ b/cookbook/tables.py @@ -1,10 +1,31 @@ import django_tables2 as tables +from django_tables2.utils import A # alias for Accessor from .models import * class RecipeTable(tables.Table): + id = tables.LinkColumn('edit_recipe', args=[A('id')]) + class Meta: model = Recipe template_name = 'tables/table_template.html' - fields = ('name', 'category', 'all_tags') + fields = ('id', 'name', 'category', 'all_tags') + + +class CategoryTable(tables.Table): + id = tables.LinkColumn('edit_recipe', args=[A('id')]) + + class Meta: + model = Category + template_name = 'tables/table_template.html' + fields = ('id', 'name') + + +class KeywordTable(tables.Table): + id = tables.LinkColumn('edit_recipe', args=[A('id')]) + + class Meta: + model = Keyword + template_name = 'tables/table_template.html' + fields = ('id', 'name') diff --git a/cookbook/templates/base.html b/cookbook/templates/base.html index dbd192191..748dbb073 100644 --- a/cookbook/templates/base.html +++ b/cookbook/templates/base.html @@ -28,7 +28,8 @@
diff --git a/cookbook/templates/new_category.html b/cookbook/templates/new_category.html index e11b36425..bcf64f9e4 100644 --- a/cookbook/templates/new_category.html +++ b/cookbook/templates/new_category.html @@ -1,6 +1,7 @@ {% extends "base.html" %} {% load crispy_forms_tags %} {% load i18n %} +{% load django_tables2 %} {% block title %}{% trans 'New Category' %}{% endblock %} @@ -15,4 +16,7 @@ {% crispy form %} + {% if table %} + {% render_table table %} + {% endif %} {% endblock %} \ No newline at end of file diff --git a/cookbook/templates/new_keyword.html b/cookbook/templates/new_keyword.html index 73a2c1f22..a5f83eaea 100644 --- a/cookbook/templates/new_keyword.html +++ b/cookbook/templates/new_keyword.html @@ -1,6 +1,7 @@ {% extends "base.html" %} {% load crispy_forms_tags %} {% load i18n %} +{% load django_tables2 %} {% block title %}{% trans 'New Keyword' %}{% endblock %} @@ -15,4 +16,7 @@ {% crispy form %} + {% if table %} + {% render_table table %} + {% endif %} {% endblock %} \ No newline at end of file diff --git a/cookbook/urls.py b/cookbook/urls.py index 664300dca..0efe9bc75 100644 --- a/cookbook/urls.py +++ b/cookbook/urls.py @@ -7,4 +7,7 @@ urlpatterns = [ path('new_recipe', views.new_recipe, name='new_recipe'), path('new_category', views.new_category, name='new_category'), path('new_keyword', views.new_keyword, name='new_keyword'), + path('edit_recipe//', views.edit_recipe, name='edit_recipe'), + path('edit_category//', views.edit_category, name='edit_category'), + path('edit_keyword//', views.new_keyword, name='edit_keyword'), ] diff --git a/cookbook/views.py b/cookbook/views.py index 8e77f5c72..f2e4e777c 100644 --- a/cookbook/views.py +++ b/cookbook/views.py @@ -1,11 +1,10 @@ -from django.utils.translation import gettext as _ from django.contrib.auth.decorators import login_required from django.shortcuts import render, redirect from django_tables2 import RequestConfig from cookbook.filters import RecipeFilter from cookbook.forms import * -from cookbook.tables import RecipeTable +from cookbook.tables import RecipeTable, CategoryTable, KeywordTable def index(request): @@ -20,6 +19,21 @@ def index(request): return render(request, 'index.html') +@login_required +def edit_recipe(request, id): + return render(request, 'index.html') + + +@login_required +def edit_category(request, id): + return render(request, 'index.html') + + +@login_required +def edit_keyword(request, id): + return render(request, 'index.html') + + @login_required def new_recipe(request): if request.method == "POST": @@ -44,11 +58,14 @@ def new_category(request): category = form.save(commit=False) category.created_by = request.user.id category.save() - return redirect('index') + return redirect('new_category') else: form = CategoryForm() - return render(request, 'new_category.html', {'form': form}) + table = CategoryTable(Category.objects.all()) + RequestConfig(request, paginate={'per_page': 25}).configure(table) + + return render(request, 'new_category.html', {'form': form, 'table': table}) @login_required @@ -59,8 +76,11 @@ def new_keyword(request): keyword = form.save(commit=False) keyword.created_by = request.user.id keyword.save() - return redirect('index') + return redirect('new_keyword') else: form = KeywordForm() - return render(request, 'new_keyword.html', {'form': form}) + table = KeywordTable(Keyword.objects.all()) + RequestConfig(request, paginate={'per_page': 25}).configure(table) + + return render(request, 'new_keyword.html', {'form': form, 'table': table}) diff --git a/db.sqlite3 b/db.sqlite3 index 5369eba29..9bf2ffcfb 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ