How to create a unique slug in Django

后端 未结 12 534
栀梦
栀梦 2020-12-04 22:17

I am trying to create a unique slug in Django so that I can access a post via a url like this: http://www.example.com/buy-a-new-bike_Boston-MA-02111_2

The relevant m

12条回答
  •  既然无缘
    2020-12-04 23:00

    My little code:

    def save(self, *args, **kwargs):
        strtime = "".join(str(time()).split("."))
        string = "%s-%s" % (strtime[7:], self.title)
        self.slug = slugify(string)
        super(Need, self).save()
    

提交回复
热议问题