{% extends 'base/base.html' %}
{% block content %}
{% csrf_token %}
<link rel="stylesheet" href="/media/static/css/request/jquery-ui.css">
<link rel="stylesheet" href="/media/static/css/request/Table.css">
<script src="/media/static/js/request/jquery-3.6.0.js"></script>
<script src="/media/static/js/request/jquery-ui.js"></script>
<script>
$(function() {
$("#id_Customers_full_name").autocomplete({
source: "{% url 'autocomplete_cus' %}",
});
});
</script>
<script>
$(function() {
$("#id_Lecture_hall").autocomplete({
source: "{% url 'autocomplete_lec' %}",
});
});
</script>
<br>
<div class="card mx-3" style="width: 850px;"><h5
class="card-header">Поиск по заявкам:</h5>
<div class="card-body">
<h6 class="card-subtitle mb-2 text-muted">Введите один или несколько параметров:</h6>
<div class="d-flex">
<form method="get">
<div class="row">
<div class="col">
<input class="form-control" type="number" name="id" id="id_id" placeholder="ID"
aria-label="default input example">
</div>
<div class="col">
<input class="form-control" type="text" name="Customers_full_name" id="id_Customers_full_name"
placeholder="Заказчик" aria-label="default input example">
</div>
<div class="col">
<input class="form-control" type="text" name="Lecture_hall" id="id_Lecture_hall"
placeholder="Аудитория"
aria-label="default input example">
</div>
<div class="col">
<select name="Condition"
class="form-select"
style="width: 200px;"
id="id_Condition">
<option value="" selected="">---Состояние---</option>
{% for item in condition %}
<option value="{{ item.id }}">{{ item.Condition }}</option>
{% endfor %}
</select>
</div>
<div class="col mx-3">
<button class="btn btn-primary" type="submit">Поиск</button>
</div>
</div>
</form>
</div>
</div>
</div>
<br>
<div class="content mx-3">
<h2>
Список заявок
</h2>
<br>
<!---------Таблица начало---------->
<table id="table" class="table table-bordered">
<thead>
<!---------Заголовки----------->
<tr>
<th>ID</th>
<th>Заказчик</th>
<th>Аудитория</th>
<th>Описание</th>
<th>Тип работ</th>
<th>Дата заявки</th>
<th>Исполнитель</th>
<th>Комментарий</th>
<th>Состояние</th>
<th>Файлы</th>
</tr>
</thead>
<!----------------------------->
<!-----------Ячейки таблицы---->
<tbody>
{% for item in page_obj %}
<tr>
<td><a href="{{ item.id }}/update">{{ item.id }}</a></td>
<td>{{ item.Customers_full_name }}</td>
<td>{{ item.Lecture_hall }}</td>
<td>{{ item.Description }}</td>
<td>{{ item.Work.Type_of_work }}</td>
<td>{{ item.Request_date }}</td>
<td>{{ item.Performer.Full_name_of_the_performer }}</td>
<td>{{ item.Comment }}</td>
<td>{{ item.Condition }}</td>
{% load static %}
<td><a href="media/{{ item.Files }}" target="_blank">{{item.Files}}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
<br>
{% include 'request/pagination.html' %}
<br>
</div>
<!--------------------------------->
{% endblock %}
@login_required(login_url='login/')
@permission_required('request.view_request')
def index(request):
requests = Request.objects.all()
condition = Condition_list.objects.all()
myFilter = RequestFilter(request.GET, queryset=requests)
requests = myFilter.qs
# search by single word
search_query = request.GET.get("Customers_full_name")
if search_query:
requests = Request.objects.filter(Customers_full_name__icontains=search_query)
##
m = []
k = 0
for i in requests:
k += 1
m.append(k)
# set up pagination
paginator = Paginator(requests, 5)
page_number = request.GET.get('page')
page_obj = paginator.get_page(page_number)
paginator_obj = Paginator(m, 5).get_page(page_number)
##
context = {'requests': requests, 'myFilter': myFilter, 'condition': condition, 'page_obj': page_obj,
'paginator_obj': paginator_obj}
return render(request, 'request/request.html', context)
class Request(models.Model):
...
Files = models.FileField(upload_to='./static' + '/files' + '/%Y/%m/%d/', verbose_name='Загрузка файла', blank=True)
...
def split_files(self):
return ''.join(re.split('static/', self.Files.name))
STATIC_URL = 'static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_URL = 'media/'
MEDIA_ROOT = os.path.join('media')