coding utf-8 from django db import models import datetime Create your

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- coding:utf-8 -*-
from django.db import models
import datetime
# Create your models here.
class Authors(models.Model):
"""Класс автора"""
name_author = models.CharField(max_length=32)
date_reg = models.DateTimeField('user added')
def __unicode__(self):
return self.name_author
class Admin:
pass
class MainMessage(models.Model):
"""Класс сообщения на главной странице"""
allText = models.TextField()
author_mes = models.ForeignKey(Authors)
date_mes = models.DateTimeField('message add')
news_header = models.CharField(max_length=64)
def get_short_mes(self):
if len(self.allText) > 300 :
return " ".join(self.allText[:300].split(" ")[:-1]) + u'... <a href="post_%d">Дальше </a>' % self.id
else:
return self.allText
def was_published(self):
return self.date_mes.date() == datetime.date.today()
def __unicode__(self):
return self.allText
class Admin:
pass
class Comment(models.Model):
"""Класс комментарии, связаный с сообщением"""
comment_author = models.CharField(max_length=32)
comment_ip = models.IPAddressField()
comment_date = models.DateTimeField('comment add')
comment_text = models.TextField()
comment_mes = models.ForeignKey(MainMessage)
def __unicode__(self):
return self.comment_author
class Admin:
pass