Ejemplo n.º 1
0
class Tag(models.Model):
    name = models.CharField(_("Name"), max_length=255, unique=True)
    created = AutoCreatedField(_('Created'))
    uuid = models.UUIDField(unique=True, default=uuid4, editable=False)

    objects = TagQuerySet.as_manager()

    def __str__(self):
        return "#%s" % self.name

    def get_absolute_url(self):
        return reverse('streams:tag', kwargs={"name": slugify(self.name)})

    def save(self, *args, **kwargs):
        """Ensure name is lower case and stripped.

        Note this could lead to unique constraints when saving - make sure to also lower case and trim
        the name when fetching tags, or use the given manager for that.
        """
        self.name = self.name.strip().lower()
        super().save()

    @cached_property
    def channel_group_name(self):
        """Make a safe Channel group name.

        ASCII or hyphens or periods only.
        """
        # TODO use just id
        return ("%s_%s" % (self.id, slugify(self.name)))[:80]
Ejemplo n.º 2
0
class Tag(models.Model):
    name = models.CharField(_("Name"), max_length=255, unique=True)
    created = AutoCreatedField(_('Created'))

    objects = TagQuerySet.as_manager()

    def __str__(self):
        return "#%s" % self.name

    def save(self, *args, **kwargs):
        """Ensure name is lower case and stripped.

        Note this could lead to unique constraints when saving - make sure to also lower case and trim
        the name when fetching tags, or use the given manager for that.
        """
        self.name = self.name.strip().lower()
        super().save()

    @cached_property
    def channel_group_name(self):
        """Make a safe Channel group name.

        ASCII or hyphens or periods only.
        Prefix with ID as we have to slugify the name and cut long guids due to asgi library group name restriction.
        """
        return ("%s_%s" % (self.id, slugify(self.name)))[:80]
Ejemplo n.º 3
0
class Tag(models.Model):
    name = models.CharField(_("Name"), max_length=255, unique=True)
    created = AutoCreatedField(_('Created'))

    objects = TagQuerySet.as_manager()

    def __str__(self):
        return "#%s" % self.name

    def save(self, *args, **kwargs):
        """Ensure name is lower case and stripped.

        Note this could lead to unique constraints when saving - make sure to also lower case and trim
        the name when fetching tags, or use the given manager for that.
        """
        self.name = self.name.strip().lower()
        super().save()