from django.db import models import datetime from django.utils import timezone from django.core.paginator import Paginator class Category(models.Model): name=models.CharField(max_length=50) created_at = models.DateTimeField(auto_now_add=True) class User(models.Model): name = models.CharField(max_length=20) created_at = models.DateTimeField(auto_now_add=True) class Post(models.Model): text = models.TextField() created_at = models.DateTimeField(auto_now_add=True) authors=models.ManyToManyField(User) author_anonim_name = models.TextField() category = models.ForeignKey(Category, on_delete=models.CASCADE) @staticmethod def getPostsOfAuthor(author): return Post.objects.filter(authors=author) @staticmethod def getYesterday(): y=(datetime.datetime.today() - datetime.timedelta(days=1)) return Post.objects.filter(created_at__day=y.day, created_at__month=y.month, created_at__year=y.year) @staticmethod def getTodays(): return Post.objects.filter(created_at__day=datetime.datetime.now().date().day) @staticmethod def getPage(page:int): a = Post.objects.all().order_by('created_at') paginator = Paginator(a,5) return paginator.get_page(page) class StaticPage(models.Model): own_text = models.TextField() post = models.ForeignKey(Post,on_delete=models.CASCADE) class MenuEntry(models.Model): link = models.TextField() alt = models.TextField() class Menu(models.Model): entry = models.ManyToManyField(MenuEntry) class Comment(models.Model): post = models.ForeignKey(Post,on_delete=models.CASCADE) author=models.ForeignKey(User,on_delete=models.CASCADE, default=None, null=True) unregistered_author = models.CharField(max_length=20) text = models.TextField() class Config(models.Model): topMenu = models.ForeignKey(Menu, on_delete=models.CASCADE)