Days counting in Django model for graph generation

I wanted to get work statistics from the date of the first entry. I had problems with the while loop as I had to specify an iteration limit.
In order to find out the number of days since the first entry, I decided to subtract the date of the first entry from today’s date.



I then used the resulting number for my while loop.

field_name = 'date_added'
obj = Addinfo.objects.first()
field_object = Addinfo._meta.get_field(field_name)
first_date_full = field_object.value_from_object(obj)
first_date =
delta = - first_date
n = delta.days

x = []
y = []
i = 0
while i<=n:
    daywork = -i
    dayview = Addinfo.objects.filter(date_added__day=daywork).values_list('work_minutes', flat=True)
    y.append(sum([int(minn) for minn in dayview]))
    i += 1

chart = get_plot_svg(x, y)

See also  iLo server power on Python script for Telegram Bot
Author: admin

Leave a Reply

Your email address will not be published. Required fields are marked *