Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.db import models
- from django.db.models.deletion import CASCADE, PROTECT
- from django.utils.translation import ugettext_lazy as _
- from django.utils import timezone
- class Conso(models.Model):
- utlisateur = models.CharField(max_length=100, blank=True, null=True)
- coun_mat = models.IntegerField(blank=True)
- date = models.DateTimeField(blank=True)
- OBS = models.CharField(max_length=200, blank=True, null=True)
- class Meta:
- db_table= "Conso"
- ordering = ['-date']
- ################### views.py
- from datetime import datetime, date
- def index(request, year, month): # to get month you should do this
- today = date.today()
- mat = Conso.objects.filter(date__year=year, date__month=month)
- mat = Conso.objects.filter(date__year=today.year, date__month=today.month)
- # this is an example for explanation
- income = Visits.objects.values('visitdate').filter(visitdate__year=2020, visitdate__month=12)
- print(income, income[0], income[0]['visitdate'], income[0]['visitdate'].month)
- # <QuerySet [{'visitdate': datetime.date(2020, 12, 29)}]> {'visitdate': datetime.date(2020, 12, 29)} 2020-12-29 12
- ### mat = Conso.objects.all()
- context = {
- 'form':mat,
- 'month': income[0]['visitdate'].month,
- }
- return render (request, 'index.html', context)
- templates
- {% for i in form %}
- {% if == %}
- ملاحظة اريد القيام بشرط بالشهر
- {{i.utlisateur}}
- {{i.coun_mat}}
- {% endif%}
- {% endfor%}
Add Comment
Please, Sign In to add comment