From 5ac9f32bde7b37ef4802027715f906210c08a04c Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Sun, 17 Sep 2023 19:25:44 +0800 Subject: [PATCH] Improved admin panel for student status subject selection and removed redundant wait for redis py function --- stude/student_status/admin.py | 27 +++++++++++++++++++++++++++ stude/wait_for_redis.py | 14 -------------- 2 files changed, 27 insertions(+), 14 deletions(-) delete mode 100644 stude/wait_for_redis.py diff --git a/stude/student_status/admin.py b/stude/student_status/admin.py index fbfe8be..a5d8c0b 100644 --- a/stude/student_status/admin.py +++ b/stude/student_status/admin.py @@ -1,10 +1,37 @@ from django.contrib import admin from .models import StudentStatus from leaflet.admin import LeafletGeoAdmin +from django import forms +from subjects.models import SubjectInstance +from accounts.models import CustomUser + + +class CustomStudentStatusForm(forms.ModelForm): + def __init__(self, *args, **kwargs): + super(CustomStudentStatusForm, self).__init__(*args, **kwargs) + if self.instance: + studentstatus = StudentStatus.objects.filter( + user=self.instance.user).first() + user = CustomUser.objects.filter( + id=studentstatus.user.id).first() + subjects = SubjectInstance.objects.filter( + course=user.course) + self.fields['subject'].queryset = subjects + + subject = forms.ModelMultipleChoiceField( + queryset=SubjectInstance.objects.none(), required=False) + avatar = forms.ImageField(required=False) + + class Meta: + model = StudentStatus + fields = '__all__' class StudentStatusAdmin(LeafletGeoAdmin): + model = StudentStatus + form = CustomStudentStatusForm # define which fields are required + def get_form(self, request, obj=None, **kwargs): form = super(StudentStatusAdmin, self).get_form(request, obj, **kwargs) form.base_fields['landmark'].required = False diff --git a/stude/wait_for_redis.py b/stude/wait_for_redis.py deleted file mode 100644 index 0b68f4e..0000000 --- a/stude/wait_for_redis.py +++ /dev/null @@ -1,14 +0,0 @@ -import time -import os -import redis - -REDIS_HOST = os.getenv('REDIS_HOST', 'localhost') -REDIS_PORT = os.getenv('REDIS_PORT', 6379) -if __name__ == '__main__': - while True: - try: - redis.Redis(host=REDIS_HOST, port=REDIS_PORT) - print('Redis is up!') - break - except redis.ConnectionError: - time.sleep(0.1)