i’m poor with django.
i have a project and project has an app
in my app, i have a models.py and includes
from django.db import models
from taggit.managers import TaggableManager
class Post(models.Model):
title = models.CharField(max_length=100)
body = models.TextField()
created = models.DateTimeField()
tags = TaggableManager()
def __unicode__(self):
return self.title
and i also add this models.py
posts = Post.objects.all().order_by(“-created”)[:2]
Is it the right way to keep it here?
Some examples shows that queries in models.py some are in views.py ?
Also can i use posts in my mysite/templates ?
The best way to do this is to create a custom manager with a method that performs the query when called. That way you don’t need to worry about it being cached, recycled, etc.