mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-17 06:19:24 +08:00
Commit migrations and fixed pruning crontab command not setting student status to False. Also fixed Student Status subject field in admin
This commit is contained in:
parent
87d1bcb04f
commit
a58142030d
3 changed files with 31 additions and 3 deletions
|
@ -35,6 +35,7 @@ class Command(BaseCommand):
|
|||
# Set the fields of the old statuses to the required values
|
||||
for status in old_statuses:
|
||||
logger.info(f'Resetting StudentStatus: {status}')
|
||||
status.active = False
|
||||
status.location = Point(0, 0)
|
||||
status.subject = None
|
||||
status.landmark = None
|
||||
|
|
|
@ -4,8 +4,10 @@ from leaflet.admin import LeafletGeoAdmin
|
|||
from django import forms
|
||||
from subjects.models import SubjectInstance, Subject
|
||||
from accounts.models import CustomUser
|
||||
from django.contrib.gis.geos import Point
|
||||
|
||||
|
||||
# Unused. To reimplement down the line
|
||||
class CustomStudentStatusForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(CustomStudentStatusForm, self).__init__(*args, **kwargs)
|
||||
|
@ -23,9 +25,8 @@ class CustomStudentStatusForm(forms.ModelForm):
|
|||
# Filter the Subject objects by these names
|
||||
subjects = Subject.objects.filter(name__in=subject_instance_names)
|
||||
self.fields['subject'].queryset = subjects
|
||||
# To fix: study group is still empty despite student already joined one
|
||||
subject = forms.ModelChoiceField(
|
||||
queryset=Subject.objects.none(), required=False)
|
||||
queryset=Subject.objects.all(), required=False)
|
||||
|
||||
class Meta:
|
||||
model = StudentStatus
|
||||
|
@ -34,12 +35,20 @@ class CustomStudentStatusForm(forms.ModelForm):
|
|||
|
||||
class StudentStatusAdmin(LeafletGeoAdmin):
|
||||
model = StudentStatus
|
||||
form = CustomStudentStatusForm
|
||||
# define which fields are required
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
if obj.active is False:
|
||||
obj.location = Point(0, 0)
|
||||
obj.subject = None
|
||||
obj.landmark = None
|
||||
obj.study_group = None
|
||||
super().save_model(request, obj, form, change)
|
||||
|
||||
def get_form(self, request, obj=None, **kwargs):
|
||||
form = super(StudentStatusAdmin, self).get_form(request, obj, **kwargs)
|
||||
form.base_fields['landmark'].required = False
|
||||
form.base_fields['study_group'].required = False
|
||||
return form
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 4.2.5 on 2023-10-13 04:23
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('study_groups', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='studygroup',
|
||||
name='timestamp',
|
||||
field=models.DateTimeField(auto_now_add=True),
|
||||
),
|
||||
]
|
Loading…
Reference in a new issue