2019-11-25 12:18:15 +01:00
|
|
|
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)
|
2020-01-20 18:36:06 +01:00
|
|
|
author_anonim_name = models.TextField(null=True)
|
|
|
|
category = models.ForeignKey(Category, on_delete=models.CASCADE, null=True)
|
2019-11-25 12:18:15 +01:00
|
|
|
@staticmethod
|
2020-01-12 17:55:22 +01:00
|
|
|
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
|
2019-11-25 12:18:15 +01:00
|
|
|
def getTodays():
|
2020-01-12 17:55:22 +01:00
|
|
|
return Post.objects.filter(created_at__day=datetime.datetime.now().date().day)
|
2019-11-25 12:18:15 +01:00
|
|
|
@staticmethod
|
|
|
|
def getPage(page:int):
|
2020-01-20 18:36:06 +01:00
|
|
|
a = Post.objects.all().order_by('-created_at' )
|
|
|
|
paginator = Paginator(a,3)
|
2019-11-25 12:18:15 +01:00
|
|
|
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)
|
2020-01-20 14:59:40 +01:00
|
|
|
author=models.ForeignKey(User,on_delete=models.CASCADE, default=None, null=True)
|
2019-11-25 12:18:15 +01:00
|
|
|
unregistered_author = models.CharField(max_length=20)
|
|
|
|
text = models.TextField()
|
|
|
|
class Config(models.Model):
|
|
|
|
topMenu = models.ForeignKey(Menu, on_delete=models.CASCADE)
|