kin*_*iyk 1 python django django-templates social-networking instagram
我正在尝试实现 Twitter 等社交网站上使用的“@”功能,以标记或提及我的 django 项目中的用户。例如,单击“@stack”时应转到堆栈的配置文件。
如何做到这一点对我很有帮助。
编辑器上处理的提及系统对吗?这是django-markdown-editor提供直接提及 user @[username]
=> @username
另请参阅有关 function markdown_find_mentions
,如果您需要为其他用户提到的用户实现通知系统(例如 stackoverflow),则很有用。
def markdown_find_mentions(markdown_text):
"""
To find the users that mentioned
on markdown content using `BeautifulShoup`.
input : `markdown_text` or markdown content.
return : `list` of usernames.
"""
mark = markdownify(markdown_text)
soup = BeautifulSoup(mark, 'html.parser')
return list(set(
username.text[1::] for username in
soup.findAll('a', {'class': 'direct-mention-link'})
))
Run Code Online (Sandbox Code Playgroud)
这是一个简单的流程;
确保通知有发送者和接收者。
class Notification(TimeStampedModel):
sender = models.ForeignKey(User, related_name='sender_n')
receiver = models.ForeignKey(User, related_name='receiver_n')
content_type = models.ForeignKey(ContentType, related_name='n', on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id')
read = models.BooleanField(default=False)
....
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2899 次 |
最近记录: |