ToDo list functionality for my Work Accounting Project

There was a need to separate completed tasks from open ones.

I added new object to model:

STATE_TYPES = (
    (0, 'Open'),
    (1, 'Done'),
    )
class Addinfo(models.Model):
"""Dobavleniy zapisi o rabote"""
.........................
    work_state = models.IntegerField(choices=STATE_TYPES, default=0, null=True)
    class Meta:
        verbose_name_plural = 'addinfos'
    def ___str___(self):
    """Vernut predstavlenie modeli"""
        return self.work_state

 

Then add new filter variables to views.py:

@login_required
def showinfo(request):
"""Show all entries"""
    q = request.GET.get('q')
    current_month = datetime.now().month
    minutes = Addinfo.objects.filter(date_added__month=current_month).values_list('work_minutes', flat=True)
    summa = sum([int(minute) for minute in minutes])
    hours = (summa // 60)
    if q:
        vector = SearchVector('work_where', 'work_who', 'work_what', 'work_comment', 'work_trade')
        query = SearchQuery(q)
        showinfoopen = Addinfo.objects.annotate(search=vector).filter(search=query).filter(work_state=0).order_by('-date_added')
        showinfodone = Addinfo.objects.annotate(search=vector).filter(search=query).filter(work_state=1).order_by('-date_added')
    else:
        showinfoopen = Addinfo.objects.filter(work_state=0).order_by('-date_added')
        showinfodone = Addinfo.objects.filter(work_state=1).order_by('-date_added')
    context = {'showinfoopen': showinfoopen, 'showinfodone': showinfodone, 'summa': summa, 'hours': hours}
    return render(request, 'reportss/showinfo.html', context)

 

See also  How to be always online in Telegram? -Python/Telethon

For nice view of data you need make some changes with template:

Don’t forget apply model changes to your ModelForm.

RESULTS:

Author: admin

Leave a Reply

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