mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-17 06:19:24 +08:00
Improved admin panel for student status subject selection and removed redundant wait for redis py function
This commit is contained in:
parent
4161e3f89c
commit
5ac9f32bde
2 changed files with 27 additions and 14 deletions
|
@ -1,10 +1,37 @@
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from .models import StudentStatus
|
from .models import StudentStatus
|
||||||
from leaflet.admin import LeafletGeoAdmin
|
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):
|
class StudentStatusAdmin(LeafletGeoAdmin):
|
||||||
|
model = StudentStatus
|
||||||
|
form = CustomStudentStatusForm
|
||||||
# define which fields are required
|
# define which fields are required
|
||||||
|
|
||||||
def get_form(self, request, obj=None, **kwargs):
|
def get_form(self, request, obj=None, **kwargs):
|
||||||
form = super(StudentStatusAdmin, self).get_form(request, obj, **kwargs)
|
form = super(StudentStatusAdmin, self).get_form(request, obj, **kwargs)
|
||||||
form.base_fields['landmark'].required = False
|
form.base_fields['landmark'].required = False
|
||||||
|
|
|
@ -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)
|
|
Loading…
Reference in a new issue