vbv/server/vbv_lernwelt/learning_mentor/models.py

26 lines
716 B
Python

from django.db import models
from vbv_lernwelt.core.models import User
from vbv_lernwelt.course.models import CourseSessionUser
class LearningMentor(models.Model):
mentor = models.OneToOneField(User, on_delete=models.CASCADE)
course = models.ForeignKey("course.Course", on_delete=models.CASCADE)
participants = models.ManyToManyField(
CourseSessionUser,
related_name="participants",
blank=True,
)
class Meta:
unique_together = [["mentor", "course"]]
def __str__(self):
return f"{self.mentor} ({self.course.title})"
@property
def course_sessions(self):
return self.participants.values_list("course_session", flat=True).distinct()