diff --git a/serviceCRM/settings.py b/serviceCRM/settings.py index 5f38c6e..f480f5b 100644 --- a/serviceCRM/settings.py +++ b/serviceCRM/settings.py @@ -41,7 +41,8 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'crispy_forms', - 'crispy_bootstrap5' + 'crispy_bootstrap5', + 'django_tables2', ] CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5" CRISPY_TEMPLATE_PACK = "bootstrap5" diff --git a/serviceCRM/tables.py b/serviceCRM/tables.py new file mode 100644 index 0000000..d0b1e28 --- /dev/null +++ b/serviceCRM/tables.py @@ -0,0 +1,7 @@ +import django_tables2 as tables +from .models import Insert + +class InsertTable(tables.Table): + class Meta: + model = Insert + template_name="base.html" \ No newline at end of file diff --git a/serviceCRM/templates/base.html b/serviceCRM/templates/base.html index e8931e3..2ccd992 100644 --- a/serviceCRM/templates/base.html +++ b/serviceCRM/templates/base.html @@ -4,9 +4,15 @@ + + Service + + + +
diff --git a/serviceCRM/templates/serviceCRM/list.html b/serviceCRM/templates/serviceCRM/list.html new file mode 100644 index 0000000..1530944 --- /dev/null +++ b/serviceCRM/templates/serviceCRM/list.html @@ -0,0 +1,6 @@ +{% extends 'base.html' %} +{% load render_table from django_tables2 %} +{% block content %} + {% render_table object_list %} + +{% endblock%} \ No newline at end of file diff --git a/serviceCRM/urls.py b/serviceCRM/urls.py index 25e4890..4f881a2 100644 --- a/serviceCRM/urls.py +++ b/serviceCRM/urls.py @@ -16,12 +16,13 @@ Including another URLconf """ from django.contrib import admin from django.urls import include, path -from serviceCRM.views import ReportById,index,InsertNew,done +import serviceCRM.views as view urlpatterns = [ - path("", index, name="index"), + path("", view.index, name="index"), path('admin/', admin.site.urls), - path("/", ReportById.ReportById, name="detail"), - path("insert/",InsertNew.insert, name="insert"), - path("done/",done,name="done") -] \ No newline at end of file + path("/", view.ReportById.ReportById, name="detail"), + path("insert/", view.InsertNew.insert, name="insert"), + path("done/", view.done, name="done"), + path("list/", view.List.as_view(), name="list") +] diff --git a/serviceCRM/views.py b/serviceCRM/views.py index 476fab5..644d690 100644 --- a/serviceCRM/views.py +++ b/serviceCRM/views.py @@ -4,11 +4,11 @@ from .models import Insert from django.views import generic from .forms import InputForm -from django.template import loader +# from django.template import loader def index(request): - proba = Insert.objects.order_by("name") + proba = Insert.objects.order_by("date") return HttpResponse(proba) @@ -17,13 +17,6 @@ def index(request): # context = {"name":req.name, "phone":req.phone,"desc":req.description,"date":req.date} # return HttpResponse(render(request,"serviceCRM/id.html", context)) # - -def inputform(request): - if request.method == 'POST': - if request.POST.get(): - return - - class ReportById(generic.DetailView): model = Insert template_name = "serviceCRM/id.html" @@ -37,9 +30,10 @@ class ReportById(generic.DetailView): class InsertNew(generic.View): model = Insert template_name = "serviceCRM/form.html" + def insert(request): if request.method == 'POST': - form=InputForm(request.POST) + form = InputForm(request.POST) if form.is_valid(): form.save() print("Raboti") @@ -47,11 +41,17 @@ class InsertNew(generic.View): else: form = InputForm() - return render(request,InsertNew.template_name,{'form':form}) + return render(request, InsertNew.template_name, {'form': form}) -def done(request,question_id): +class List(generic.ListView): + model = Insert + template_name = "serviceCRM/list.html" + + +def done(request, question_id): req = get_object_or_404(Insert, id=question_id) if req.isDone(): return HttpResponse("Done") return HttpResponse("Not Done") +