amr_aly

Hakim Zerrouki

May 30th, 2021 (edited)
921
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ## in your views.py
  2. from django.db.models import Count
  3. from django.http import request
  4. from django.shortcuts import render
  5. from .models import Dashbord
  6. from .forms import DashbordForm
  7. # Create your views here.
  8.  
  9. def index(request):
  10.    
  11.     if request.method == 'POST':
  12.         form = DashbordForm(request.Post)
  13.         if form.is_valid():
  14.             form.save()
  15.  
  16.     # count_name = Dashboard.objects.values('name').annotate(ncount=Count('name')).filter(name='IMPREMENT')
  17.     count_name = Dashbord.objects.filter(name='IMPRIMENT').count()
  18.     count_number = count_name[0]['ncount']
  19.  
  20.     context = {
  21.         'consomable': Dashbord.objects.all(),
  22.         'count_number': count_number,
  23.     }
  24.     return render (request, 'index.html', context)
  25.  
  26.  
  27. #### in your html file
  28.  
  29. <div>
  30.     <h1>IMPREMENT = {{count_number}}</h1>
  31. </div>
RAW Paste Data