pracowniapp2/przyrost/models.py

47 lines
1.8 KiB
Python
Raw Normal View History

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)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
@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):
a = Post.objects.all()
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)
unregistered_author = models.CharField(max_length=20)
text = models.TextField()
class Config(models.Model):
topMenu = models.ForeignKey(Menu, on_delete=models.CASCADE)