adding features for social network

This commit is contained in:
2026-04-18 13:31:20 +02:00
parent 1bc57a99ce
commit 043e866ac9
7 changed files with 177 additions and 13 deletions

View File

@@ -1,3 +1,42 @@
from django.db import models
# Create your models here.
from django.conf import settings
import magic
mime = magic.Magic(mime=True)
class Post(models.Model):
content = models.TextField(blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
author = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name='posts'
)
hub = models.ForeignKey(
'pages.Hub',
on_delete=models.CASCADE,
null=True,
blank=True
)
def __str__(self):
return f"Post {self.id}"
class PostContent(models.Model):
post = models.ForeignKey(Post, related_name='contents', on_delete=models.CASCADE)
mime_type = models.CharField(max_length=100)
file = models.FileField(upload_to='post_contents/', null=True, blank=True) # For images/videos
alt_text = models.TextField(blank=True, null=True) # For text content
def __str__(self):
return f"Content for Post {self.post.id} - Type: {self.mime_type}"
def save(self, *args, **kwargs):
if self.file and not self.file._committed:
self.mime_type = mime.from_buffer(self.file.read(1024))
return super().save(*args, **kwargs)