コード例 #1
0
class Author(models.Model):
    """
    An author is everyone who wrote or has contributed to write a post.
    """
    name = models.CharField(_("Name"),
                            max_length=255,
                            null=True,
                            blank=True,
                            db_index=True)
    email = models.EmailField(_("Author email"), blank=True)
    profile_url = models.URLField(_("Profile URL"), blank=True, null=True)

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

    class Meta:
        verbose_name = _("Author")
        verbose_name_plural = _("Authors")
        ordering = ('name', 'email')

    def __unicode__(self):
        return u"%s (%s)" % (
            self.name,
            self.email,
        )

    @models.permalink
    def get_absolute_url(self):
        return ('planet.views.author_detail', [str(self.id)])
コード例 #2
0
class Author(models.Model):
    """
    An author is everyone who wrote or has contributed to write a post.
    """
    name = models.CharField(_("Name"), max_length=255, null=True,
        blank=True, db_index=True)
    email = models.EmailField(_("Author email"), blank=True, db_index=True)
    profile_url = models.URLField(_("Profile URL"), blank=True, null=True)

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

    class Meta:
        verbose_name = _("Author")
        verbose_name_plural = _("Authors")
        ordering = ('name', 'email')

    def __str__(self):
        return "{} ({})".format(self.name, self.email)

    def get_absolute_url(self):
        return reverse('planet_author_detail', args=[str(self.id), self.get_slug()])

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