开发者

Override Django Slug

I have a blog in wagtail. Wagtail's default Page model already has a slug field defined. Full Example is here

slug = models.SlugField(
        verbose_name=_("slug"),

I have a Subclass AddStory of the Page class, so I am unable to define slug there. And I am getting a clashing error.

Problem:

The slug field automatically generates a slug from the Title. So There are some kind of event whose title will be same always. Like Jokes of the day, So for the first 10 or 20 days, editors will know that they have added 20 posts with day_1,day_2... at the end of the slug and when these days will increase it will be impossible for them to remember how many they have entered?!

Probable Solution

So if I can automate the slug as it will generate a slug from random ids or strings and it will be unique.

I tried this in the subclass开发者_如何学编程 AddStory

def pre_save(self):
    def randomid1(self):
        return(get_random_string(length=10))
    self.slug = randomid1

How can I define that it will not generate slug from the title instead it will generate a slug from given random strings?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜