Added django_tables2 for table listing

This commit is contained in:
ferdzo
2023-04-18 15:48:11 +02:00
parent d6b2c4d097
commit 06a3c54028
6 changed files with 40 additions and 19 deletions

View File

@@ -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"

7
serviceCRM/tables.py Normal file
View File

@@ -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"

View File

@@ -4,9 +4,15 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"/>
<title>Service </title>
</head>
<body>
<script src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.20/jquery.datetimepicker.full.min.js"></script>
<div class="container">
<div class="row justify-content-center">
<div class="col-8">

View File

@@ -0,0 +1,6 @@
{% extends 'base.html' %}
{% load render_table from django_tables2 %}
{% block content %}
{% render_table object_list %}
{% endblock%}

View File

@@ -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("<int:question_id>/", ReportById.ReportById, name="detail"),
path("insert/",InsertNew.insert, name="insert"),
path("done/<int:question_id>",done,name="done")
]
path("<int:question_id>/", view.ReportById.ReportById, name="detail"),
path("insert/", view.InsertNew.insert, name="insert"),
path("done/<int:question_id>", view.done, name="done"),
path("list/", view.List.as_view(), name="list")
]

View File

@@ -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")