2023-06-26 22:06:05 +08:00
|
|
|
from django.db import models
|
|
|
|
from accounts.models import CustomUser
|
2023-07-09 19:00:47 +08:00
|
|
|
from django.contrib.gis.db import models as gis_models
|
2023-08-06 14:19:55 +08:00
|
|
|
from django.db.models.signals import post_save
|
|
|
|
from django.dispatch import receiver
|
2023-06-26 22:06:05 +08:00
|
|
|
# Create your models here.
|
|
|
|
|
|
|
|
|
|
|
|
class StudentStatus(models.Model):
|
|
|
|
user = models.OneToOneField(
|
2023-10-02 00:46:44 +08:00
|
|
|
CustomUser, on_delete=models.CASCADE, unique=True)
|
2023-07-14 23:55:54 +08:00
|
|
|
location = gis_models.PointField(blank=True, null=True, srid=4326)
|
2023-06-27 21:12:03 +08:00
|
|
|
subject = models.ForeignKey(
|
2023-09-06 18:13:21 +08:00
|
|
|
'subjects.Subject', on_delete=models.SET_NULL, null=True, to_field='name')
|
2023-06-26 23:50:55 +08:00
|
|
|
active = models.BooleanField(default=False)
|
2023-08-15 18:53:10 +08:00
|
|
|
timestamp = models.DateTimeField(auto_now_add=True)
|
2023-07-14 23:55:54 +08:00
|
|
|
landmark = models.ForeignKey(
|
|
|
|
'landmarks.Landmark', on_delete=models.SET_NULL, null=True)
|
2023-09-25 21:09:31 +08:00
|
|
|
study_group = models.ForeignKey(
|
|
|
|
'study_groups.StudyGroup', on_delete=models.SET_NULL, null=True, related_name='students')
|
2023-07-10 17:20:15 +08:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.user.full_name
|
2023-08-06 14:19:55 +08:00
|
|
|
|
|
|
|
|
|
|
|
@receiver(post_save, sender=CustomUser)
|
|
|
|
def create_student_status(sender, instance, created, **kwargs):
|
|
|
|
if created:
|
|
|
|
if instance.is_student:
|
|
|
|
StudentStatus.objects.create(user=instance)
|