django app 逻辑提示
我正在学习 Django,因此我正在开发一个如下所述的应用程序。
该应用程序允许用户(经过身份验证的和匿名的)向其他用户发送消息。
经过身份验证的用户可以发送消息,并且可以像使用此功能的所有应用程序一样简单地跟踪所有消息。 (例如 Facebook 消息)
问题在于匿名用户。我希望匿名用户可以向其他用户发送消息,但他可以仅跟踪他的会话的消息。用户还可以回复匿名用户的消息,但如果匿名用户丢失了他的会话,他的消息也会丢失。
问题是,如何管理匿名用户及其会话的消息?
I'm learning Django and for this reason I'm developing an application described below.
This application allows users (authenticated and anonymous) to send message to other users.
Authenticated users can send message and can track all messages simply as all application that uses this feature. (like Facebook messages, for example)
The problem are anonymous users. I would an anonymous user can send message to other users but he can track his messages only for his session. Users can also reply to a message of an anonymous user but If an anonymous user lost his session lost also his messages.
The problem is, how can I manage anonymous user and their messages for the session only?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Django 支持匿名会话。
如果您的应用程序相对简单(听起来确实如此),我会执行以下操作:
他们在会话中的临时配置文件 ID。
其 id 不在会话表中。一种简单的方法(也是我会做的)是在配置文件上创建一个创建的日期/时间字段,然后删除两周或更长时间前创建的并且具有空用户字段的任何配置文件。我只是 crontab 一个 django 管理命令。
很酷的是,如果有人在匿名使用该应用程序一段时间后注册,您可以使用他们的临时个人资料作为他们的个人资料,并且他们会保留他们的消息。
Django supports anonymous sessions.
If your app is relatively simple (it sounds like it is), I would do the following:
their temporary profile id in their session.
whose id is not in the sessions table. A simple way (and what I would do) is have a created date/time field on the profile and just delete any profile that was created two weeks or more ago and has a null user field. I'd just crontab a django management command.
The cool thing is that if somebody registers after using the app anonymously for a while you can use their temporary profile as their profile and they keep their messages.