evg-app-back/lessons/models.py

102 lines
3.1 KiB
Python
Raw Normal View History

2021-01-10 15:51:59 +03:00
from django.db import models
from organisations.models import Organisation, Teacher, Group, Child
from django.dispatch import receiver
from django.db.models.signals import post_save
class Subject(models.Model):
name = models.CharField(max_length=100)
organisation = models.ForeignKey(Organisation, on_delete=models.CASCADE)
teachers_give = models.ManyToManyField(Teacher)
class SubjectClassLocal(models.Model):
subject = models.ForeignKey(Subject, on_delete=models.CASCADE)
teachers = models.ManyToManyField(Teacher)
group = models.ForeignKey(Group, on_delete=models.CASCADE)
name = models.CharField(max_length=100, unique=False)
def __str__(self):
return self.name
class Lesson(models.Model):
type_lesson = models.ForeignKey(SubjectClassLocal, on_delete=models.CASCADE)
2021-01-20 22:10:57 +03:00
name = models.TextField(default="")
descr = models.TextField(default="")
content = models.TextField(default="")
time_lesson = models.DateTimeField(auto_now=True)
2021-01-10 15:51:59 +03:00
class Materials(models.Model):
link = models.URLField()
name = models.CharField(max_length=100, blank=True)
data = models.TextField(blank=True)
Type = models.CharField(max_length=100, default="link")
lesson = models.ForeignKey(Lesson, on_delete=models.CASCADE, default=3)
2021-01-10 15:51:59 +03:00
class Tests(models.Model):
name = models.CharField(max_length=150)
deadline = models.DateTimeField()
lesson = models.ForeignKey(Lesson, on_delete=models.CASCADE)
2021-02-26 13:59:01 +03:00
is_timing = models.BooleanField(default=False)
time_sec = models.IntegerField(default=300)
2021-01-10 15:51:59 +03:00
class Type(models.Model):
name = models.TextField(max_length=150)
2021-02-06 11:37:54 +03:00
class TaskType(models.Model):
name = models.TextField()
2021-02-26 13:59:01 +03:00
def __str__(self) :
return self.name
2021-01-10 15:51:59 +03:00
class Task(models.Model):
theory = models.TextField()
practise = models.TextField()
2021-02-06 11:37:54 +03:00
test = models.ManyToManyField(Tests)
2021-01-20 22:10:57 +03:00
types = models.ManyToManyField(Type)
2021-01-10 15:51:59 +03:00
number = models.IntegerField()
2021-01-20 22:10:57 +03:00
max_score = models.IntegerField(default=0)
2021-02-06 11:37:54 +03:00
is_timing = models.BooleanField(default=False)
time = models.IntegerField(default=30)
Type = models.ForeignKey(TaskType, on_delete=models.CASCADE)
is_autoCheck = models.BooleanField(default=False)
autoCheckData = models.TextField(blank=True)
2021-01-10 15:51:59 +03:00
2021-02-06 11:37:54 +03:00
2021-01-10 15:51:59 +03:00
class Theme(models.Model):
tasks = models.ManyToManyField(Task)
name = models.CharField(max_length=150)
class AnswerSheet(models.Model):
child = models.ForeignKey(Child, on_delete=models.CASCADE)
completed = models.BooleanField(default=False)
test = models.ForeignKey(Tests, on_delete=models.CASCADE)
class Answer(models.Model):
sheet = models.ForeignKey(AnswerSheet, on_delete=models.CASCADE)
content = models.TextField()
number = models.IntegerField()
2021-01-20 22:10:57 +03:00
completed = models.BooleanField(default=False)
2021-03-20 02:32:12 +03:00
score = models.IntegerField(default=0)
@receiver(post_save, sender=AnswerSheet)
def createUserAnswers(sender, instance, created, **kwargs):
print(sender, instance)
for task in instance.test.task_set.all():
print(task, instance.test.task_set.all())
Answer.objects.create(sheet=instance, content="", number=task.number)
@receiver(post_save, sender=Answer)
def answerR(sender, instance, **kwargs):
print(instance, instance.sheet, instance.sheet.child)