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.

 

>>>>>>UPDATED INFO! CLICK HERE<<<<<<<

I then used the resulting number for my while loop.

#COUNTING DAYS
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 = first_date_full.date()
delta = datetime.now().date() - first_date
n = delta.days

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

chart = get_plot_svg(x, y)

See also  Updated Django model days counting - month start error
Author: admin

Leave a Reply

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