models.py
1.94 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from django.db import models
from autoslug.fields import AutoSlugField
from django.utils.translation import ugettext_lazy as _
from users.models import User
from django.core.exceptions import ValidationError
from categories.models import Category
import datetime
class Tag(models.Model):
name = models.CharField( _("Name"), unique = True,max_length= 200)
def __str__(self):
return self.name
class Subject(models.Model):
name = models.CharField( _("Name"), unique = True,max_length= 200)
slug = AutoSlugField(_("Slug"),populate_from='name',unique=True)
description_brief = models.TextField(_("simpler_description"), blank=True)
description = models.TextField(_("description"), blank= True)
visible = models.BooleanField(_("visible"))
init_date = models.DateField(_('Begin of Subject Date'))
end_date = models.DateField(_('End of Subject Date'))
tags = models.ManyToManyField(Tag, verbose_name='tags', blank=True)
create_date = models.DateTimeField(_('Creation Date'), auto_now_add = True)
update_date = models.DateTimeField(_('Date of last update'), auto_now=True)
subscribe_begin = models.DateField(_('Begin Subscribe'))
subscribe_end = models.DateField(_('End Subscribe'))
professor = models.ManyToManyField(User, related_name="professors", blank=True)
students = models.ManyToManyField(User,verbose_name=_('Students'), related_name='subject_student', blank = True)
category = models.ForeignKey(Category, related_name="subject_category", null=True)
max_upload_size = models.IntegerField(_("Maximum upload size"), default=1024, null=True)
class Meta:
verbose_name = "Subject"
verbose_name_plural = "Subjects"
ordering = ['name']
def __str__(self):
return self.name
# def clean(self):
# if self.subscribe_begin > self.end_date:
# raise ValidationError(_('Subscribe period should be between course time'))