From e9dc2dc48f463145b20632bcbbc6c3767b87b15c Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 1 Feb 2018 15:34:43 +0100 Subject: [PATCH] edit + tables --- .idea/workspace.xml | 200 +++++++++++---------------- cookbook/tables.py | 23 ++- cookbook/templates/base.html | 24 ++-- cookbook/templates/new_category.html | 4 + cookbook/templates/new_keyword.html | 4 + cookbook/urls.py | 3 + cookbook/views.py | 32 ++++- db.sqlite3 | Bin 172032 -> 172032 bytes 8 files changed, 154 insertions(+), 136 deletions(-) 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 5369eba294c135f5a19d136bc7421e7bbb9479c7..9bf2ffcfb8ba7cdc967606ef5e6ad5c8f6b90330 100644 GIT binary patch delta 223 zcmZoTz}0YoYl1Xm*F+g-#;%PCZ2F9>&FT8>>H3V@)AgC=Ch)QH)iCgH;?Lxl<2%Gx zvsqCgi?7~=m7PJJ)6tRFBeArgBt0=N-N?YuLf61Z*T7K0(8S8f#LC!Q&&1f=(9j6C zOcV>m6idIvMa7JBBUrly7_C^E`cMo=j;Q)45zZUv`QpczG}nMtL2 L>C@%rGd%(T&SW_p delta 55 zcmZoTz}0YoYl1Xm$3z)t#*U2%Z2FAM&FT8>>H3V@)AgC=CU7zH%Q5h8;?Lxl+pK6H Lz&~AXKGP!r+k_Ab