Django query get recent record for each entry and display as combined list
Posted
by gtujan
on Stack Overflow
See other posts from Stack Overflow
or by gtujan
Published on 2010-04-14T08:44:00Z
Indexed on
2010/04/15
1:03 UTC
Read the original article
Hit count: 286
I have two models device and log setup as such:
class device(models.Model):
name = models.CharField(max_length=20)
code = models.CharField(max_length=10)
description = models.TextField()
class log(model.Model):
device = models.ForeignKey(device)
date = models.DateField()
time = models.TimeField()
data = models.CharField(max_length=50)
how do I get a list which contains only the most recent record/log (based on time and date) for each device and combine them in the format below:
name,code,date,time,data
being a Django newbie I would like to implement this using Django's ORM. TIA!
© Stack Overflow or respective owner