Hallo people,
I have two Models, Thread and Post, where one Thread can have many Posts. I want to retrieve the active threads by sorting by 'post_set.createtime'. In the end, I want to get exactly ten Threads that had the most recent activity. Is this possible using no own SQL?
Thanks a lot in advance.
[Copying the model definitions from the OP's reply to the body of the question.]
class Topic(models.Model):
title = models.CharField(max_length=50)
order = models.SmallIntegerField() #used for visual stuff
class Thread(models.Model):
topic = models.ForeignKey(Topic)
name = models.CharField(max_length=50)
class Post(Meta):
thread = models.ForeignKey(Thread)
text = models.TextField()
class Meta(models.Model):
createuser = models.ForeignKey(User,default=None,blank=True,null=True,related_name="createuser")
createtime = models.DateTimeField(default=datetime.datetime.now,blank=True,null=True)
edituser = models.ForeignKey(User,default=None,null=True,related_name="edituser",blank=True)
edittime = models.DateTimeField(default=None,null=True,blank=True)