Hallo people
I have two models, topics and posts in which one thread can have many posts. I want to get active threads sorting by 'post_set.createtime'. In the end, I want to get exactly ten threads that have the most recent activity. Is this possible using native SQL?
Thank you very much in advance.
[Copying model definitions from the OP answer to the body of the question.]
class Topic(models.Model):
title = models.CharField(max_length=50)
order = models.SmallIntegerField()
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)
wicht
source
share