Skip to content

Instantly share code, notes, and snippets.

@jeyraof
Last active August 29, 2015 14:14
Show Gist options
  • Save jeyraof/7b224b98ec2406ac8d8b to your computer and use it in GitHub Desktop.
Save jeyraof/7b224b98ec2406ac8d8b to your computer and use it in GitHub Desktop.
class User(models.Model):
~~~~
class Post(models.Model):
author = models.ForeignKey(User)
column_a = modelsIntegerField(default=0)
@property
def comments(self):
return self.comment_list.order_by('created_at')
class Comment(models.Model):
author = models.ForeignKey(User)
post = models.ForeignKey(Post, related_name='comment_list')
tmp = []
for j in tmp_list:
tmp += Post.objects.filter(column_a=int(j)).select_related('author',
'comment_list',
'comment_list__author')
# pass tmp to template,
# and Use tmp.comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment