I've added some comments to your code, please let me know if something's still unclear so I can update it with more information:
class ArticlePkAndSlug(models.Model):
title = models.CharField(max_length=settings.BLOG_TITLE_MAX_LENGTH)
# editable=False means that slug will be created only once and then it won't be updated
slug = models.SlugField(default="", editable=False, max_length=settings.BLOG_TITLE_MAX_LENGTH)
def get_absolute_url(self):
# this method returns an absolute URL to object details, which consists of object ID and its slug
kwargs = {"pk": self.id, "slug": self.slug}
return reverse("article-pk-slug-detail", kwargs=kwargs)
def save(self, *args, **kwargs):
value = self.title
self.slug = slugify(value, allow_unicode=True)
# here the title of an article is slugifyed, so it can be easily used as a URL param
super().save(*args, **kwargs)
https://stackoverflow.com/questions/427102/what-is-a-slug-in-django?rq=1 – John Albert Flores May 10 '20 at 11:58