Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###### in templates file.html
- {% url 'your_app_name:your_function_name' as month_url %}
- <form class="form-inline mt-2 mt-md-0 float-left" method="GET" action="{{month_url}}">
- <input class="form-control mr-sm-2" type="text" name='name' placeholder="Patient Name ..."
- value="{{request.GET.name}}" aria-label="Search">
- <button class="btn btn-secondary my-2 my-sm-0" type="submit" hidden>Search</button>
- </form>
- {% block content %}
- {% for obj in patient %}
- <p>obj.databasefield1</p>
- <p>obj.databasefield2</p>
- <p>obj.databasefield3</p>
- {% endfor %}
- {% endblock %}
- ################### in views.py
- from django.shortcuts import render, redirect
- from django.urls import reverse
- from django.db.models import Q
- from .models import Visits
- from .tables import VisitsTable
- from datetime import date
- def calculate_month_income(request):
- today = date.today() # datetime.now()
- month_income = Visits.objects.filter(visitdate__year=today.year, visitdate__month=today.month)
- search_name = request.GET.get('name')
- #search_month = request.GET.get('month')
- if search_name == None and search_month == None:
- table = VisitsTable(month_income, exclude='addpresent')
- table.paginate(page=request.GET.get("page", 1), per_page=10)
- # elif ('month' in request.GET) and request.GET['month']:
- # result_month = Visits.objects.filter(Q(visitdate__year=today.year, visitdate__month=search_month))
- # table = VisitsTable(result_month, exclude='addpresent')
- # table.paginate(page=request.GET.get("page", 1), per_page=5)
- elif ('name' in request.GET) and request.GET['name'].strip():#
- patient = Visits.objects.filter(Q(patient__name__icontains=search_name,
- visitdate__year=today.year, visitdate__month=today.month))
- return redirect(reverse('your_app_name:function_name'))
- #table = VisitsTable(patient, exclude='addpresent')
- #table.paginate(page=request.GET.get("page", 1), per_page=10)
- else:
- table = VisitsTable(month_income, exclude='addpresent')
- table.paginate(page=request.GET.get("page", 1), per_page=10)
- context = {
- 'patient': patient,
- #'month_table': table,
- }
- return render(request, 'reports/month_table.html', context)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement