Don’t forget to enter notes” – If they have not enter note by today and enter note the prior day

Issue

I have two tables
Member table and Daily_Notes table.

class Member(models.Model):
    name = models.Charfield()

Daily_notes table

class DailyNotes(models.Model):
    member= models.Foreignkey('Member')
    note=models.Charfield()
    date=models.Datetimefield(default="")

Daily note table contains daily entries

I need to filter datas, If user have not enter note by today and entered the prior day.

Solution

You can retrieve Members that have filled in a DailyNotes item the previous day and not the current day with:

from datetime import date, timedelta

Member.objects.filter(
    dailynotes__date__date=date.today() - timedelta(days=1)
).exclude(
    dailynotes__date__date=date.today()
)

Answered By – Willem Van Onsem

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published