Reputation: 37
Trying this syntax to populate a column from other columns.
SELECT CONCAT('Oferta,',`id`, ',', `nazwa`) as slug FROM `maszyny`;
Here 'Oferta' is hard coded string. Its showing a result with above concat format but column 'slug' didnt populate with data. What i am missing?
Upvotes: 0
Views: 45
Reputation: 1090
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)
Upvotes: 1