mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2025-06-28 16:25:44 +08:00
CustomUser and StudentStatus improvements
This commit is contained in:
parent
d6bef3a231
commit
06441702c7
18 changed files with 48 additions and 82 deletions
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 4.2.3 on 2023-07-26 12:06
|
||||
# Generated by Django 4.2.3 on 2023-08-06 05:55
|
||||
|
||||
from django.conf import settings
|
||||
import django.contrib.gis.db.models.fields
|
||||
|
@ -11,8 +11,8 @@ class Migration(migrations.Migration):
|
|||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('landmarks', '0001_initial'),
|
||||
('accounts', '0002_initial'),
|
||||
('landmarks', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 4.2.3 on 2023-07-26 12:06
|
||||
# Generated by Django 4.2.3 on 2023-08-06 05:55
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
@ -9,9 +9,9 @@ class Migration(migrations.Migration):
|
|||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('student_status', '0001_initial'),
|
||||
('study_groups', '0001_initial'),
|
||||
('subjects', '0001_initial'),
|
||||
('student_status', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
from django.db import models
|
||||
from accounts.models import CustomUser
|
||||
from study_groups.models import StudyGroup
|
||||
from django.contrib.gis.db import models as gis_models
|
||||
from django.contrib.gis.geos import Point
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
# Create your models here.
|
||||
|
||||
|
||||
|
@ -21,3 +21,10 @@ class StudentStatus(models.Model):
|
|||
|
||||
def __str__(self):
|
||||
return self.user.full_name
|
||||
|
||||
|
||||
@receiver(post_save, sender=CustomUser)
|
||||
def create_student_status(sender, instance, created, **kwargs):
|
||||
if created:
|
||||
if instance.is_student:
|
||||
StudentStatus.objects.create(user=instance)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from django.urls import path
|
||||
from django.urls import path, include
|
||||
from rest_framework.routers import DefaultRouter
|
||||
from .views import StudentStatusAPIView, ActiveStudentStatusListAPIView
|
||||
|
||||
urlpatterns = [
|
||||
|
|
|
@ -8,9 +8,10 @@ class StudentStatusAPIView(generics.RetrieveUpdateAPIView):
|
|||
serializer_class = StudentStatusSerializer
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
def get_object(self):
|
||||
def get_queryset(self):
|
||||
user = self.request.user
|
||||
return StudentStatus.objects.get(user=user)
|
||||
queryset = StudentStatus.objects.filter(user=user)
|
||||
return queryset
|
||||
|
||||
|
||||
class ActiveStudentStatusListAPIView(generics.ListAPIView):
|
||||
|
@ -19,4 +20,4 @@ class ActiveStudentStatusListAPIView(generics.ListAPIView):
|
|||
|
||||
def get_queryset(self):
|
||||
user = self.request.user
|
||||
return StudentStatus.objects.filter(active=True)
|
||||
return StudentStatus.objects.filter(user != user).filter(active=True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue