Django-注册自定义值以共享网址

时间:2019-06-25 17:22:28

标签: python django

我要添加共享功能。我想在模型中注册它应该具有的后缀,然后构建器应该从中构建一个URL(当然,还要重定向用户)。

示例: example.com/article/the-best-article应转换为以下形式:example.com/sU74?a(这只是一个随机ID)

另一个例子: example.com/poll/what-is-your-thought应转换为: example.com/sU74?p(这些ID是相同的,但它们是不同的模型!)

我想用这种方式注册后缀:

class Poll(RandomIdMixin):
    # RandomIdMixin is a abstract model which creates random ids for the model
    # some fields
    @share.register
    def suffix(self):
        return "p"

    def share_builder(self):
        # return shared builder
        # this should return the short url

我不知道这是否可行。谢谢您的帮助

0 个答案:

没有答案