Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.db import models
- from django.utils.text import slugify
- class Article(models.Model):
- title = models.CharField(max_length=255)
- content = models.TextField()
- slug = models.SlugField(unique=True, blank=True)
- def save(self, *args, **kwargs):
- if not self.slug:
- self.slug = slugify(self.title)
- super().save(*args, **kwargs)
- # Създаване на нова статия
- article = Article(title="Django Tips", content="Some useful tips for Django developers.")
- article.save() # Slug ще бъде генериран автоматично, ако не е предоставен
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement