add chat
This commit is contained in:
36
prompt/models.py
Normal file
36
prompt/models.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import uuid
|
||||
from django.db import models
|
||||
from django_extensions.db.models import TimeStampedModel
|
||||
from account.models import User
|
||||
from task.models import Task
|
||||
|
||||
|
||||
class Conversation(TimeStampedModel):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="conversations")
|
||||
task = models.ForeignKey(Task, on_delete=models.CASCADE, related_name="conversations")
|
||||
is_active = models.BooleanField(default=True, verbose_name="是否活跃")
|
||||
|
||||
class Meta:
|
||||
ordering = ("-created",)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.user.username} - {self.task.title}"
|
||||
|
||||
|
||||
class Message(models.Model):
|
||||
conversation = models.ForeignKey(
|
||||
Conversation, on_delete=models.CASCADE, related_name="messages"
|
||||
)
|
||||
role = models.CharField(max_length=10) # "user" or "assistant"
|
||||
content = models.TextField()
|
||||
code_html = models.TextField(null=True, blank=True)
|
||||
code_css = models.TextField(null=True, blank=True)
|
||||
code_js = models.TextField(null=True, blank=True)
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ("created",)
|
||||
|
||||
def __str__(self):
|
||||
return f"[{self.role}] {self.content[:50]}"
|
||||
Reference in New Issue
Block a user