我要添加共享功能。我想在模型中注册它应该具有的后缀,然后构建器应该从中构建一个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
我不知道这是否可行。谢谢您的帮助