Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #views.py
- def patient_list(request):
- #Hit Database
- patient_list = PatientModel.objects.filter(is_deleted=False).order_by('-created_at')
- #Hit Database Again
- active_patient=patient_list.filter(patient_status='Active').aggregate(total=Sum('id'))
- #Hit Database Again
- in_active_patient=patient_list.filter(patient_status='Inactive').aggregate(total=Sum('id'))
- if request.GET.get('request_for_search') == "request_for_search":
- if request.GET.get('patient_name'):
- patient_name = request.GET.get('patient_name').strip()
- print(patient_name)
- patient_list = patient_list.filter(patient_name__icontains=patient_name)
- if request.GET.get('patient_phone'):
- patient_phone = request.GET.get('patient_phone').strip()
- patient_list = patient_list.filter(patient_phone__icontains=patient_phone)
- if request.GET.get('patient_status'):
- patient_list = patient_list.filter(patient_status=request.GET.get('patient_status'))
- else:
- paginator = Paginator(patient_list, 25)
- page = request.GET.get('page')
- patient_list = paginator.get_page(page)
- context = {
- 'patient_list': patient_list
- }
- return render(request, 'backend/Patient/patient_list.html', context)
- #models.py
- class PatientModel(models.Model):
- patient_name = models.CharField(max_length=150, db_index=True)
- patient_phone = models.CharField(max_length=20, unique=True, db_index=True)
- patient_alternative_phone = models.CharField(max_length=20, db_index=True)
- patient_email = models.EmailField(max_length=50, blank=True)
- patient_address = models.TextField()
- patient_status = models.CharField(max_length=20, db_index=True)
- created_at = models.DateTimeField(auto_now_add=True)
- updated_at = models.DateTimeField(auto_now=True)
- is_deleted = models.BooleanField(default=False, db_index=True)
- deleted_at = models.DateTimeField(blank=True, null=True)
- def soft_delete(self):
- self.is_deleted = True
- self.deleted_at = timezone.now()
- self.save()
- #template
- <!-- Page Content -->
- {% extends 'backend/index.html' %}
- {% block title %} Admin|Home {% endblock title %}
- {% block main_content %}
- <div class="wraper container-fluid m-t-15">
- <div class="row">
- <div class="col-md-12">
- <div class="panel panel-default">
- <div class="panel-heading">
- <h3 class="panel-title">Patient List</h3>
- </div>
- <form method="GET" action="{% url 'patient_list' %}">
- <div class="search-area">
- <div class="col-sm-3">
- <input class="form-control" name="patient_name" value="{{request.GET.patient_name}}" placeholder="Name">
- </div>
- <div class="col-sm-3">
- <input class="form-control" name="patient_phone" value="{{request.GET.patient_phone}}" placeholder="Phone">
- </div>
- <div class="col-sm-3">
- <select class="form-control" name="patient_status">
- <option value="">--select--</option>
- <option>Active</option>
- <option>Inactive</option>
- </select>
- </div>
- <div class="col-sm-3">
- <input type="hidden" name="request_for_search" value="request_for_search">
- <button class="btn btn-primary" type="submit" ><i class="fa fa-search-plus"></i> </button>
- </div>
- </div>
- </form>
- <div class="panel-body">
- <div class="row">
- <div class="col-md-12 col-sm-12 col-xs-12">
- <table class="table table-striped table-bordered">
- <thead>
- <tr>
- <th>Sl No</th>
- <th>Patient Name</th>
- <th>Patient Phone</th>
- <th>Patient Alt. Phone</th>
- <th>Patient Address</th>
- <th>Status</th>
- <th>Action</th>
- </tr>
- </thead>
- <tbody>
- {% for patient_list_value in patient_list %}
- <tr>
- <td>{{forloop.counter}}</td>
- <td>{{patient_list_value.patient_name}}</td>
- <td>{{patient_list_value.patient_phone}}</td>
- <td>{{patient_list_value.patient_alternative_phone}}</td>
- <td>{{patient_list_value.patient_address| slice:"20"}}...</td>
- <td>
- {% if patient_list_value.patient_status == 'Active'%}
- <span class="text-success">
- <i class="fa fa-check-circle"></i>
- {{patient_list_value.patient_status}}
- </span>
- {% else %}
- <span class="text-danger">
- <i class="fa fa-times-circle"></i>
- {{patient_list_value.patient_status}}
- </span>
- {% endif %}
- </td>
- <td>
- <a href="{% url 'patient_delete' patient_list_value.pk %}">
- <button class="btn btn-danger">
- <i class="fa fa-trash-o"></i>
- </button>
- </a>
- <a href="{% url 'patient_edit' patient_list_value.pk %}">
- <button class="btn btn-info">
- <i class="fa fa-pencil-square-o"></i>
- </button>
- </a>
- <a href="{% url 'patient_status' patient_list_value.pk %}">
- {% if patient_list_value.patient_status == 'Active'%}
- <button class="btn btn-warning">
- <i class="fa fa-times-circle"></i>
- </button>
- {% else %}
- <button class="btn btn-success">
- <i class="fa fa-check-circle"></i>
- </button>
- {% endif %}
- </a>
- </td>
- </tr>
- {% endfor %}
- </tbody>
- </table>
- <ul class="pagination">
- <li class="step-links">
- {% if patient_list.has_previous %}
- <a href="?page=1">« First</a>
- <a href="?page={{ patient_list.previous_page_number }}">Previous</a>
- {% endif %}
- </li>
- <li class="current">
- <span style="background-color: black;color: aliceblue">Page {{ patient_list.number }} of {{ patient_list.paginator.num_pages }}</span>
- </li>
- <li class="step-links">
- {% if patient_list.has_next %}
- <a href="?page={{ patient_list.next_page_number }}">Next</a>
- <a href="?page={{ patient_list.paginator.num_pages }}">Last »</a>
- {% endif %}
- </li>
- </ul>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <!-- End Row -->
- </div>
- </div>
- {% endblock main_content %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement