mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2025-06-29 00:35:45 +08:00
Removed associative entity between student and subject
This commit is contained in:
parent
8a42b58f87
commit
e6c4dd7b9c
27 changed files with 82 additions and 264 deletions
|
@ -5,6 +5,7 @@ from .models import CustomUser
|
|||
from year_levels.models import Year_Level
|
||||
from semesters.models import Semester
|
||||
from courses.models import Course
|
||||
from subjects.models import Subject
|
||||
|
||||
|
||||
class CustomUserForm(forms.ModelForm):
|
||||
|
@ -14,6 +15,8 @@ class CustomUserForm(forms.ModelForm):
|
|||
queryset=Semester.objects.all(), required=False)
|
||||
course = forms.ModelChoiceField(
|
||||
queryset=Course.objects.all(), required=False)
|
||||
subjects = forms.ModelMultipleChoiceField(
|
||||
queryset=Subject.objects.all(), required=False)
|
||||
avatar = forms.ImageField(required=False)
|
||||
|
||||
class Meta:
|
||||
|
@ -27,7 +30,7 @@ class CustomUserAdmin(UserAdmin):
|
|||
|
||||
fieldsets = UserAdmin.fieldsets + (
|
||||
(None, {'fields': ('student_id_number',
|
||||
'year_level', 'semester', 'course', 'avatar', 'is_student', 'is_banned')}),
|
||||
'year_level', 'semester', 'course', 'subjects', 'avatar', 'is_student', 'is_banned')}),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 4.2.3 on 2023-07-09 10:57
|
||||
# Generated by Django 4.2.3 on 2023-07-18 07:43
|
||||
|
||||
import accounts.models
|
||||
import django.contrib.auth.models
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 4.2.3 on 2023-07-09 10:57
|
||||
# Generated by Django 4.2.3 on 2023-07-18 07:43
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
@ -9,11 +9,11 @@ class Migration(migrations.Migration):
|
|||
initial = True
|
||||
|
||||
dependencies = [
|
||||
('courses', '0002_initial'),
|
||||
('auth', '0012_alter_user_first_name_max_length'),
|
||||
('year_levels', '0001_initial'),
|
||||
('accounts', '0001_initial'),
|
||||
('semesters', '0001_initial'),
|
||||
('year_levels', '0001_initial'),
|
||||
('auth', '0012_alter_user_first_name_max_length'),
|
||||
('courses', '0002_initial'),
|
||||
('subjects', '0001_initial'),
|
||||
]
|
||||
|
||||
|
@ -36,7 +36,7 @@ class Migration(migrations.Migration):
|
|||
migrations.AddField(
|
||||
model_name='customuser',
|
||||
name='subjects',
|
||||
field=models.ManyToManyField(related_name='SubjectStudent_user', through='subjects.SubjectStudent', to='subjects.subject'),
|
||||
field=models.ManyToManyField(to='subjects.subject'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='customuser',
|
||||
|
|
|
@ -53,8 +53,7 @@ class CustomUser(AbstractUser):
|
|||
on_delete=models.SET_NULL,
|
||||
null=True
|
||||
)
|
||||
subjects = models.ManyToManyField(
|
||||
'subjects.Subject', through='subjects.SubjectStudent', related_name='SubjectStudent_user')
|
||||
subjects = models.ManyToManyField('subjects.Subject')
|
||||
|
||||
@property
|
||||
def full_name(self):
|
||||
|
@ -78,3 +77,22 @@ def create_superuser(sender, **kwargs):
|
|||
# Activate the superuser
|
||||
superuser.is_active = True
|
||||
superuser.save()
|
||||
|
||||
User = CustomUser
|
||||
username = 'keannu125'
|
||||
email = os.getenv('DJANGO_ADMIN_EMAIL')
|
||||
password = os.getenv('DJANGO_ADMIN_PASSWORD')
|
||||
first_name = 'Keannu'
|
||||
last_name = 'Bernasol'
|
||||
# course = 'Bachelor of Science in Information Technology'
|
||||
# year_level = '1st Year'
|
||||
# semester = '1st Semester'
|
||||
|
||||
if not CustomUser.objects.filter(username=username).exists():
|
||||
# Create the superuser with is_active set to False
|
||||
user = CustomUser.objects.create(
|
||||
username=username, email=email, password=password, first_name=first_name, last_name=last_name)
|
||||
|
||||
# Activate the superuser
|
||||
user.is_active = True
|
||||
user.save()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue