Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Need help in Python Django for fetch the records from DB which will expire in 30 days

I wrote an application where there is a requirment to display only those records which will expire is next 30 day.

models.py

class SarnarLogs(models.Model):
request_type_choice = (
    ('NAR', 'NAR'),
)
source = models.CharField(max_length=100)
expiry_date = models.DateField()

def __str__(self):
    return self.source

Views.py

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@login_required(login_url=('/login'))
def expiry_requests(request):
Thirty_day = end_date = datetime.now().date() + timedelta(days=30)
posts = SarnarLogs.expiry_date.filter(expiry_date = Thirty_day)

context = {"console_data": posts, "user":request.user.full_name}
return render(request, 'expiry_requests.html', context=context)

>Solution :

You can use range:

posts = SarnarLogs.expiry_date.filter(expiry_date__range = (datetime.now().date(), Thirty_day))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading