What happens here? How do I solve this problem?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAL-bCoy-SMKGDhOPdrBStDtzx5a3f2LxHAj%3DfCX_5%3DyrdCXNSw%40mail.gmail.com.
What happens here? How do I solve this problem?
--
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CADTS2YzWi%3D2R5AsVKEnAn_HJ3syvFxS7DanmQb%2BPqLu64qF7ug%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMXTB%3DcA44t63_n4WnRtDOBq1KXMG%3DmdyLDqOBQduiAxFPqmgA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CADTS2Ywn4Oz48PjgRjuQcOUN8SXZtj_hEW89wz3xJdYA_KSY8Q%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAL-bCoyMdEHK5eUOg%2BRoCBoz2x2msEmvPBEbXQCCT0iFTx%2Bq4A%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAL-bCowOJtd4L%3DFzaUjuRAN6F6L-ApZVjLZ4Ro5YYNySWFBG3Q%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMXTB%3DcdAVucSz%2B6JXuyMrU1schTdpETC%3DD48Zd3xcy58KwJpg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAL-bCowqULQbtTcHQYxyuGd5dwxXCvqq1-asyqsrGBqP3kF3sg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAL-bCowqULQbtTcHQYxyuGd5dwxXCvqq1-asyqsrGBqP3kF3sg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJY8mfwsXL0%2BGFg90MoDL0Fm%2B9DmqKn_6%2BGuEApZZn5tG5zuMA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAL-bCowFmAnc5CKzubj29_P-t4hjF0pWW-Qu5%3Df_3zPrGAFadA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJY8mfwa1%2BzcU6XWAUbh03GOzW2wW7oZeWs_yz2KYo8YFeyQ8w%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAL-bCozXuxA6P7p%2B8oWMSHC5AdGHPNJu7NASKnhgF1-OKj8N0A%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJY8mfy-whjF08WZHdb3ywFuoKxFY%3DHYaVGVh9G5NXq4vrsBMw%40mail.gmail.com.
def _get_unique_slug(self): slug = slugify(self.blog_title) | |
unique_slug = slug | |
num = 1 | |
while Blog.objects.filter(slug=unique_slug).exists(): | |
unique_slug = '{}-{}'.format(slug, num) | |
num += 1 | |
return unique_slug |
def save(self, *args, **kwargs): | |
if not self.slug: |
self.slug = self._get_unique_slug() | |
super().save(*args, **kwargs) |
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAL-bCowowRBboKcy3fSttF__ZmLBwY1ey2MK9Tx5t8DoNdJxpA%40mail.gmail.com.
Just adding to the previous answer, you should always make sure your slug field is unique when saving, as sometimes two posts can have the same title and that would result to an error.
sorry def _get_unique_slug(self): slug = slugify(self.blog_title)