wertyveryu

rahul drahul d
1 min read
class Tag(models.Model):
    name = models.CharField(max_length=100, unique=True)
    slug = models.SlugField(max_length=50, unique=True, blank=True)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = slugify(self.name)  
        super().save(*args, **kwargs)

    def __str__(self):
        return self.name
0
Subscribe to my newsletter

Read articles from rahul d directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

rahul d
rahul d