Skip to content

Instantly share code, notes, and snippets.

@Konark-Web
Created March 22, 2021 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Konark-Web/e71f36e3407f858da9a45c353356456e to your computer and use it in GitHub Desktop.
Save Konark-Web/e71f36e3407f858da9a45c353356456e to your computer and use it in GitHub Desktop.
views.py
def list_of_vaccinations(request):
result_edit = False
if request.method == "POST":
if request.META.get('HTTP_REFERER').find('edit'):
vaccine = Vaccine.objects.get(id=request.POST.get('id'))
if vaccine:
vaccine.name = request.POST.get('name')
vaccine.date = request.POST.get('date')
vaccine.patient_id = request.POST.get('user_id')
vaccine.save()
result_edit = True
else:
vaccine = Vaccine(date=request.POST.get('date'), name=request.POST.get('name'), patient_id=request.POST.get('user_id'), doctor_id=1)
vaccine.save()
data = Vaccine.objects.all()
return render(request, 'main/list-of-vaccinations.html', {'user_data': data, 'result_edit': result_edit})
def delete_vacine(request):
result = False
if request.method == 'GET':
vaccine = Vaccine.objects.filter(id=request.GET.get('id'))
if vaccine:
if vaccine.delete():
result = True
data = Vaccine.objects.all()
return render(request, 'main/list-of-vaccinations.html', {'result': result, 'user_data': data})
{% extends 'base.html' %}
{% load main_tags %}
{% block title %}Список вакцинаций{% endblock title %}
{% block content %}
<h2>Результаты поиска</h2>
<div>
<h3>Filter by default</h3>
{% if result %}
<p><b>Сеанс вакцинации успешно удалено</b></p>
{% endif %}
{% if result_edit %}
<p><b>Сеанс вакцинации успешно редактирован</b></p>
{% endif %}
{{reffer}}
{% if user_data %}
{% for data in user_data %}
<p>Дата: {{data.date|date:"Y-m-d"}}</p>
<p>Название: {{data.name}}</p>
<p>Имя пациента: {{data|get_patient_name:data.patient_id}}</p>
<p><a href="/edit-vaccine?id={{data.id}}&date={{data.date|date:'Y-m-d'}}&name={{data.name}}&patient={{data.patient_id}}">Изменить сеанс вакцинации</a></p>
<p><a href="/delete-vacine?id={{data.id}}">Удалить сеанс вакцинации</a></p>
<hr/>
{% endfor %}
{% else %}
<p>Не найдено</p>
{% endif %}
</div>
{% endblock content %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment