Advertisement
shakil_ahmmed

Load Time

Aug 18th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.81 KB | None | 0 0
  1. #views.py
  2. def patient_list(request):
  3.     #Hit Database
  4.     patient_list = PatientModel.objects.filter(is_deleted=False).order_by('-created_at')
  5.     #Hit Database Again
  6.     active_patient=patient_list.filter(patient_status='Active').aggregate(total=Sum('id'))
  7.     #Hit Database Again
  8.     in_active_patient=patient_list.filter(patient_status='Inactive').aggregate(total=Sum('id'))
  9.     if request.GET.get('request_for_search') == "request_for_search":
  10.         if request.GET.get('patient_name'):
  11.             patient_name = request.GET.get('patient_name').strip()
  12.             print(patient_name)
  13.             patient_list = patient_list.filter(patient_name__icontains=patient_name)
  14.         if request.GET.get('patient_phone'):
  15.             patient_phone = request.GET.get('patient_phone').strip()
  16.             patient_list = patient_list.filter(patient_phone__icontains=patient_phone)
  17.         if request.GET.get('patient_status'):
  18.             patient_list = patient_list.filter(patient_status=request.GET.get('patient_status'))
  19.     else:
  20.         paginator = Paginator(patient_list, 25)
  21.         page = request.GET.get('page')
  22.         patient_list = paginator.get_page(page)
  23.     context = {
  24.         'patient_list': patient_list
  25.     }
  26.     return render(request, 'backend/Patient/patient_list.html', context)
  27.  
  28. #models.py
  29. class PatientModel(models.Model):
  30.     patient_name = models.CharField(max_length=150, db_index=True)
  31.     patient_phone = models.CharField(max_length=20, unique=True, db_index=True)
  32.     patient_alternative_phone = models.CharField(max_length=20, db_index=True)
  33.     patient_email = models.EmailField(max_length=50, blank=True)
  34.     patient_address = models.TextField()
  35.     patient_status = models.CharField(max_length=20, db_index=True)
  36.     created_at = models.DateTimeField(auto_now_add=True)
  37.     updated_at = models.DateTimeField(auto_now=True)
  38.     is_deleted = models.BooleanField(default=False, db_index=True)
  39.     deleted_at = models.DateTimeField(blank=True, null=True)
  40.  
  41.     def soft_delete(self):
  42.         self.is_deleted = True
  43.         self.deleted_at = timezone.now()
  44.         self.save()
  45. #template
  46.     <!-- Page Content -->
  47. {% extends 'backend/index.html' %}
  48. {% block title %} Admin|Home {% endblock title %}
  49. {% block main_content %}
  50. <div class="wraper container-fluid m-t-15">
  51. <div class="row">
  52. <div class="col-md-12">
  53.     <div class="panel panel-default">
  54.         <div class="panel-heading">
  55.             <h3 class="panel-title">Patient List</h3>
  56.         </div>
  57.         <form method="GET" action="{% url 'patient_list' %}">
  58.             <div class="search-area">
  59.                 <div class="col-sm-3">
  60.                     <input class="form-control" name="patient_name" value="{{request.GET.patient_name}}" placeholder="Name">
  61.                 </div>
  62.                 <div class="col-sm-3">
  63.                     <input class="form-control" name="patient_phone" value="{{request.GET.patient_phone}}" placeholder="Phone">
  64.                 </div>
  65.                 <div class="col-sm-3">
  66.                     <select class="form-control" name="patient_status">
  67.                         <option value="">--select--</option>
  68.                         <option>Active</option>
  69.                         <option>Inactive</option>
  70.                     </select>
  71.                 </div>
  72.                 <div class="col-sm-3">
  73.                     <input type="hidden" name="request_for_search" value="request_for_search">
  74.                     <button class="btn btn-primary" type="submit" ><i class="fa fa-search-plus"></i> </button>
  75.                 </div>
  76.             </div>
  77.         </form>
  78.         <div class="panel-body">
  79.             <div class="row">
  80.                 <div class="col-md-12 col-sm-12 col-xs-12">
  81.             <table class="table table-striped table-bordered">
  82.                 <thead>
  83.                     <tr>
  84.                         <th>Sl No</th>
  85.                         <th>Patient Name</th>
  86.                         <th>Patient Phone</th>
  87.                         <th>Patient Alt. Phone</th>
  88.                         <th>Patient Address</th>
  89.                         <th>Status</th>
  90.                         <th>Action</th>
  91.                     </tr>
  92.                 </thead>
  93.  
  94.                 <tbody>
  95.                 {% for patient_list_value in patient_list %}
  96.                     <tr>
  97.                         <td>{{forloop.counter}}</td>
  98.                         <td>{{patient_list_value.patient_name}}</td>
  99.                         <td>{{patient_list_value.patient_phone}}</td>
  100.                         <td>{{patient_list_value.patient_alternative_phone}}</td>
  101.                         <td>{{patient_list_value.patient_address| slice:"20"}}...</td>
  102.                         <td>
  103.                             {% if patient_list_value.patient_status == 'Active'%}
  104.                                <span class="text-success">
  105.                                <i class="fa fa-check-circle"></i>
  106.                                     {{patient_list_value.patient_status}}
  107.                                </span>
  108.                             {% else %}
  109.                             <span class="text-danger">
  110.                             <i class="fa fa-times-circle"></i>
  111.                                     {{patient_list_value.patient_status}}
  112.                                </span>
  113.                             {% endif %}
  114.                         </td>
  115.                         <td>
  116.                         <a href="{% url 'patient_delete' patient_list_value.pk  %}">
  117.                             <button class="btn btn-danger">
  118.                                 <i class="fa fa-trash-o"></i>
  119.                             </button>
  120.                         </a>
  121.                         <a href="{% url 'patient_edit' patient_list_value.pk  %}">
  122.                             <button class="btn btn-info">
  123.                                 <i class="fa fa-pencil-square-o"></i>
  124.                             </button>
  125.                         </a>
  126.                             <a href="{% url 'patient_status' patient_list_value.pk  %}">
  127.                                  {% if patient_list_value.patient_status == 'Active'%}
  128.                                    <button class="btn btn-warning">
  129.                                         <i class="fa fa-times-circle"></i>
  130.                                     </button>
  131.                                  {% else %}
  132.                                     <button class="btn btn-success">
  133.                                         <i class="fa fa-check-circle"></i>
  134.                                     </button>
  135.                                 {% endif %}
  136.                             </a>
  137.  
  138.  
  139.                         </td>
  140.                     </tr>
  141.                 {% endfor %}
  142.  
  143.                 </tbody>
  144.             </table>
  145.             <ul class="pagination">
  146.                     <li class="step-links">
  147.                         {% if patient_list.has_previous %}
  148.                             <a href="?page=1">&laquo; First</a>
  149.                             <a href="?page={{ patient_list.previous_page_number }}">Previous</a>
  150.                         {% endif %}
  151.                     </li>
  152.                         <li class="current">
  153.                             <span style="background-color: black;color: aliceblue">Page {{ patient_list.number }} of {{ patient_list.paginator.num_pages }}</span>
  154.                         </li>
  155.                         <li class="step-links">
  156.                         {% if patient_list.has_next %}
  157.                             <a href="?page={{ patient_list.next_page_number }}">Next</a>
  158.                             <a href="?page={{ patient_list.paginator.num_pages }}">Last &raquo;</a>
  159.                         {% endif %}
  160.                      </li>
  161.             </ul>
  162.              </div>
  163.             </div>
  164.         </div>
  165.     </div>
  166. </div>
  167.  
  168. </div>
  169. <!-- End Row -->
  170.  
  171. </div>
  172.  
  173. </div>
  174. {% endblock main_content %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement