__models py class Post models Model blog models ForeignKey Blog poster

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
__models.py
class Post(models.Model):
blog = models.ForeignKey(Blog)
poster = models.ForeignKey(User)
caption = models.CharField(max_length=50)
content = models.TextField()
posted = models.DateTimeField()
tag = models.CharField(max_length=20, choices=TAGS)
def __unicode__(self):
return self.content
def get_absolute_url(self):
return "/archive/%s/%s/%s/%s" % (self.posted.year, self.posted.month,
self.posted.day, self.caption)
__views.py
def archives(request, year=None, month=None, day=None, caption=None):
entry = Post.objects.filter(posted__year=year, posted__month=month, posted__day=day, caption=caption)[0]
return render_to_response("archive.html", {'entry': entry})