Plankton_Detector/PlanktonDetector/Community/models.py

24 lines
762 B
Python
Raw Normal View History

2023-12-13 02:11:29 +01:00
from django.db import models
from django.contrib.auth.models import User
2024-01-07 01:10:31 +01:00
from ckeditor.fields import RichTextField
2023-12-13 02:11:29 +01:00
# Create your models here.
class Post(models.Model):
title = models.CharField(max_length=500)
2024-01-07 01:10:31 +01:00
content = RichTextField(null=True, blank=True)
2023-12-13 02:11:29 +01:00
author = models.ForeignKey(User, on_delete=models.CASCADE, null=False)
2024-01-07 01:10:31 +01:00
date_pub = models.DateTimeField(auto_now_add=True)
2023-12-13 02:11:29 +01:00
@property
def sorted_comments(self):
return self.comment_set.all().order_by("-date_added")
2023-12-13 02:11:29 +01:00
class Comment(models.Model):
author = models.ForeignKey(User, on_delete=models.CASCADE, null=False)
content = models.TextField()
post = models.ForeignKey(Post, on_delete=models.CASCADE)
2024-01-07 01:10:31 +01:00
date_added = models.DateTimeField(auto_now_add=True)