コード例 #1
0
class Blog(models.Model):
    """
    A model to store primary info about a blog or website that which feed or
    feeds are aggregated to our planet
    """
    title = models.CharField(_("title"),
                             max_length=255,
                             blank=True,
                             db_index=True)
    url = models.URLField(_("Url"), unique=True, db_index=True)
    date_created = models.DateTimeField(_("Date created"), auto_now_add=True)

    site_objects = BlogManager()
    objects = models.Manager()

    class Meta:
        verbose_name = _("Blog")
        verbose_name_plural = _("Blogs")
        ordering = (
            'title',
            'url',
        )

    def __unicode__(self):
        return u'%s (%s)' % (self.title, self.url)

    @models.permalink
    def get_absolute_url(self):
        return ('planet.views.blog_detail', [str(self.id)])
コード例 #2
0
class Blog(models.Model):
    """
    A model to store primary info about a blog or website that which feed or
    feeds are aggregated to our planet
    """

    title = models.CharField(_("title"), max_length=255, blank=True, db_index=True)
    url = models.URLField(_("Url"), unique=True, db_index=True)
    date_created = models.DateTimeField(_("Date created"), auto_now_add=True)
    owner = models.ForeignKey(_get_user_model(), null=True, blank=True)

    site_objects = BlogManager()
    objects = models.Manager()

    class Meta:
        verbose_name = _("Blog")
        verbose_name_plural = _("Blogs")
        ordering = ('title', 'url',)

    def __str__(self):
        return '{} ({})'.format(self.title, self.url)

    @models.permalink
    def get_absolute_url(self):
        return ('planet.views.blog_detail', [str(self.id), self.get_slug()])

    def get_slug(self):
        return slugify(self.title) or "no-title"