Improved admin panel for student status subject selection and removed redundant wait for redis py function

This commit is contained in:
Keannu Bernasol 2023-09-17 19:25:44 +08:00
parent 4161e3f89c
commit 5ac9f32bde
2 changed files with 27 additions and 14 deletions

View file

@ -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

View file

@ -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)