Spaces:
Running
Running
Download api/models/chat.py from Dayozoe/harvestconnect-api: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/spaces/Dayozoe/harvestconnect-api/resolve/main/api/models/chat.py
- Command line
-
hf download hf://spaces/Dayozoe/harvestconnect-api/api/models/chat.py
-
curl -L -o chat.py https://huggingface.co/spaces/Dayozoe/harvestconnect-api/resolve/main/api/models/chat.py
1.37 kB
| from django.db import models | |
| from django.contrib.auth.models import User | |
| class ChatRoom(models.Model): | |
| """Room for multiple participants to chat""" | |
| ROOM_TYPES = [ | |
| ('personal', 'Direct Message'), | |
| ('group', 'Private Group'), | |
| ('channel', 'Public Channel'), | |
| ] | |
| name = models.CharField(max_length=255) | |
| room_type = models.CharField(max_length=20, choices=ROOM_TYPES, default='personal') | |
| church = models.CharField(max_length=255, blank=True, null=True) | |
| location = models.CharField(max_length=255, blank=True, null=True) | |
| participants = models.ManyToManyField(User, related_name='chat_rooms') | |
| created_at = models.DateTimeField(auto_now_add=True) | |
| def __str__(self): | |
| return f"[{self.room_type.upper()}] {self.name}" | |
| class ChatMessage(models.Model): | |
| """Individual messages in a chat room""" | |
| room = models.ForeignKey(ChatRoom, on_delete=models.CASCADE, related_name='messages') | |
| sender = models.ForeignKey(User, on_delete=models.CASCADE, related_name='sent_messages') | |
| content = models.TextField(blank=True, default='') | |
| image = models.ImageField(upload_to='chat_images/', blank=True, null=True) | |
| timestamp = models.DateTimeField(auto_now_add=True) | |
| class Meta: | |
| ordering = ['timestamp'] | |
| def __str__(self): | |
| return f"{self.sender.username}: {self.content[:20]}" | |