1
https://github.com/nathanborror/django-basic-apps/blob/master/README.rst我想實現這個博客模塊,我的問題是,我寫一個通用的功能,當我取一個博客獲得網址爲網址在博客中的Django
def Myfunc(request):
p = Post.objects.get(pk=12)
p.get_absolute_url //This prints blog/2011/jun/13/fgfgf/
我的問題是,如何獲得與域名的URL或者這是否存在的代碼來處理..
EDIT: i.e, http://mysite.com/blog/2011/jun/13/fgfgf/
的車型領域是,
class Post(models.Model):
"""Post model."""
STATUS_CHOICES = (
(1, _('Draft')),
(2, _('Public')),
)
title = models.CharField(_('title'), max_length=200)
slug = models.SlugField(_('slug'), unique_for_date='publish')
author = models.ForeignKey(User, blank=True, null=True)
body = models.TextField(_('body'),)
tease = models.TextField(_('tease'), blank=True, help_text=_('Concise text suggested. Does not appear in RSS feed.'))
status = models.IntegerField(_('status'), choices=STATUS_CHOICES, default=2)
allow_comments = models.BooleanField(_('allow comments'), default=True)
publish = models.DateTimeField(_('publish'), default=datetime.datetime.now)
created = models.DateTimeField(_('created'), auto_now_add=True)
modified = models.DateTimeField(_('modified'), auto_now=True)
categories = models.ManyToManyField(Category, blank=True)
#created_by = models.ForeignKey(UserProfile)
tags = TagField()
objects = PublicManager()
class Meta:
verbose_name = _('post')
verbose_name_plural = _('posts')
db_table = 'blog_posts'
ordering = ('-publish',)
get_latest_by = 'publish'
def __unicode__(self):
return u'%s' % self.title
@permalink
def get_absolute_url(self):
return ('blog_detail', None, {
'year': self.publish.year,
'month': self.publish.strftime('%b').lower(),
'day': self.publish.day,
'slug': self.slug
})
着我們做同樣的Django的版本1.2.1 – Rajeev 2011-06-13 08:04:13
是的,我相信這個代碼在1.2 – Rich 2011-06-13 08:07:56