gpt4 book ai didi

django - 用户之间的消息传递应用程序模型

转载 作者:行者123 更新时间:2023-12-03 10:14:18 25 4
gpt4 key购买 nike

如何在用户之间创建消息应用程序。创建模型的业务逻辑是什么?我能想到的是这样的:

模型.py

class Message(models.Model):
description = models.TextField()
date_added = models.DateTimeField(default=datetime.now)
sender = models.ForeignKey(User)
recipient = models.ForeignKey(User)

我不太确定这是否是要走的路。如果您能指导我如何开始,将非常感谢。谢谢!

最佳答案

常见情况的变体:

from django.utils.translation import ugettext_lazy as _

class Message(models.Model):
"""
A private message from user to user
"""
subject = models.CharField(_("Subject"), max_length=120, blank=True)
body = models.TextField(_("Body"))
sender = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='sender_messages', verbose_name=_("Sender"), )
recipient = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='receiver_messages', null=True, blank=True, verbose_name=_("Recipient"))
parent_msg = models.ForeignKey('self', related_name='next_messages', null=True, blank=True, verbose_name=_("Parent message"))
sent_at = models.DateTimeField(_("sent at"), null=True, blank=True)
read_at = models.DateTimeField(_("read at"), null=True, blank=True)
replied_at = models.DateTimeField(_("replied at"), null=True, blank=True)
sender_deleted_at = models.DateTimeField(_("Sender deleted at"), null=True, blank=True)
recipient_deleted_at = models.DateTimeField(_("Recipient deleted at"), null=True, blank=True)
ip = models.GenericIPAddressField(verbose_name=_('IP'), null=True, blank=True)
user_agent = models.CharField(verbose_name=_('User Agent'), blank=True, max_length=255)

关于django - 用户之间的消息传递应用程序模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20288996/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com