Skip to content

Commit

Permalink
django models from domain model
Browse files Browse the repository at this point in the history
  • Loading branch information
sPAICEcake committed Feb 27, 2024
1 parent b8e287e commit b95a3ab
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
67 changes: 67 additions & 0 deletions api/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from django.db import models


class Student(models.Model):
student_id = models.CharField(max_length=20, unique=True)
name = models.CharField(max_length=100)
subjects = models.ManyToManyField('Vak', related_name='students_enrolled')

def __str__(self):
return self.name

class Lesgever(models.Model):
lesgever_id = models.CharField(max_length=20, unique=True)
name = models.CharField(max_length=100)
subjects = models.ManyToManyField('Vak', related_name='lesgevers_enrolled')
is_admin = models.BooleanField(default=False)

def __str__(self):
return self.name

class Vak(models.Model):
vak_id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100)
students = models.ManyToManyField('Student', related_name='subjects_enrolled', blank=True)
teachers = models.ManyToManyField('Lesgever', related_name='subjects_teachers')
projects = models.ManyToManyField('Project', related_name='subjects_projects', blank=True)

def __str__(self):
return self.name

class Groep(models.Model):
group_id = models.AutoField(primary_key=True)
students = models.ManyToManyField('Student', related_name='groups_students', blank=True)
project = models.ForeignKey('Project', on_delete=models.CASCADE)

def __str__(self):
return f"Group {self.group_id}"

class Project(models.Model):
project_id = models.AutoField(primary_key=True)
titel = models.CharField(max_length=100)
description = models.TextField()
opgavebestanden = models.FileField(upload_to='opgave/')
vak = models.ForeignKey(Vak, on_delete=models.CASCADE)
deadline = models.DateTimeField(null=True)
# indiening restricties

def __str__(self):
return self.titel

class Indiening(models.Model):
indiening_id = models.AutoField(primary_key=True)
indiener = models.ForeignKey('Groep', on_delete=models.CASCADE)
indieningsbestanden = models.FileField(upload_to='uploads/')
tijdstip = models.DateTimeField(null=False)

def __str__(self):
return self.tijdstip

class Score(models.Model):
score = models.SmallIntegerField()
indiening = models.ForeignKey('Indiening', on_delete=models.CASCADE)
groep = models.ForeignKey('Groep', on_delete=models.CASCADE)

def __str__(self):
return self.score

6 changes: 4 additions & 2 deletions api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['sel2-4.ugent.be', 'localhost']
ALLOWED_HOSTS = ['sel2-4.ugent.be', 'localhost', '127.0.0.1']


# Application definition
Expand All @@ -37,6 +37,8 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'api',
'rest_framework'
]

MIDDLEWARE = [
Expand Down Expand Up @@ -80,7 +82,7 @@
'USER': 'myprojectuser',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '',
'PORT': '5432',
}
}

Expand Down

2 comments on commit b95a3ab

@mathis2003
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zijn er hiervoor extra libraries geinstalleerd?

@sPAICEcake
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nee, enkel 'api' en 'rest_framework' zijn toegevoegd, en ik heb blijkbaar per ongeluk ook mijn allowed_host laten staan

Please sign in to comment.