Fakultas Ilmu Komputer UI

Commit cdedc068 authored by Zamil Majdy's avatar Zamil Majdy
Browse files

[#140654507] #11 Update database schema

parent b616dfb2
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-03-28 12:04
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('core', '0004_auto_20170328_1417'),
]
operations = [
migrations.CreateModel(
name='Application',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('cover_letter', models.TextField(blank=True, null=True)),
('allow_transcript', models.BooleanField(default=True)),
],
),
migrations.RemoveField(
model_name='student',
name='applied_vacancies',
),
migrations.AddField(
model_name='student',
name='applied_vacancies',
field=models.ManyToManyField(blank=True, related_name='applied_vacancies', through='core.Application', to='core.Vacancy'),
),
migrations.AddField(
model_name='application',
name='student',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Student'),
),
migrations.AddField(
model_name='application',
name='vacancy',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.Vacancy'),
),
]
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-03-28 12:50
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('core', '0005_auto_20170328_1904'),
]
operations = [
migrations.AlterUniqueTogether(
name='application',
unique_together=set([('student', 'vacancy')]),
),
]
...@@ -3,6 +3,8 @@ from core.models.accounts import Company ...@@ -3,6 +3,8 @@ from core.models.accounts import Company
from core.models.accounts import Student from core.models.accounts import Student
from core.models.accounts import Supervisor from core.models.accounts import Supervisor
from core.models.vacancies import Vacancy from core.models.vacancies import Vacancy
from core.models.vacancies import Application
...@@ -49,7 +49,8 @@ class Student(models.Model): ...@@ -49,7 +49,8 @@ class Student(models.Model):
resume = models.FileField(upload_to=get_student_resume_file_path, null=True, blank=True) resume = models.FileField(upload_to=get_student_resume_file_path, null=True, blank=True)
phone_number = models.CharField(max_length=100, blank=True, db_index=True, null=True) phone_number = models.CharField(max_length=100, blank=True, db_index=True, null=True)
bookmarked_vacancies = models.ManyToManyField('core.Vacancy', related_name="bookmarked_vacancies", blank=True) bookmarked_vacancies = models.ManyToManyField('core.Vacancy', related_name="bookmarked_vacancies", blank=True)
applied_vacancies = models.ManyToManyField('core.Vacancy', related_name="applied_vacancies", blank=True) applied_vacancies = models.ManyToManyField('core.Vacancy', related_name="applied_vacancies",
blank=True, through='core.Application')
@property @property
def name(self): def name(self):
......
from django.db import models from django.db import models
from core.models.accounts import Company from core.models.accounts import Company, Student
class Vacancy(models.Model): class Vacancy(models.Model):
...@@ -12,3 +12,14 @@ class Vacancy(models.Model): ...@@ -12,3 +12,14 @@ class Vacancy(models.Model):
created = models.DateTimeField(auto_now_add=True) created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True) updated = models.DateTimeField(auto_now=True)
name = models.CharField(max_length=100, null=False) name = models.CharField(max_length=100, null=False)
class Application(models.Model):
cover_letter = models.TextField(null=True, blank=True)
allow_transcript = models.BooleanField(null=False, default=True)
student = models.ForeignKey(Student, on_delete=models.CASCADE)
vacancy = models.ForeignKey(Vacancy, on_delete=models.CASCADE)
class Meta:
unique_together = (("student", "vacancy"),)
from rest_framework import serializers from rest_framework import serializers
from core.serializers.accounts import CompanySerializer from core.serializers.accounts import CompanySerializer, StudentSerializer
from core.models.vacancies import Vacancy from core.models.vacancies import Vacancy
...@@ -11,3 +11,14 @@ class VacancySerializer(serializers.ModelSerializer): ...@@ -11,3 +11,14 @@ class VacancySerializer(serializers.ModelSerializer):
fields = '__all__' fields = '__all__'
class ApplicationSerializer(serializers.ModelSerializer):
vacancy = VacancySerializer()
student = StudentSerializer()
class Meta:
model = Vacancy
fields = '__all__'
...@@ -5,8 +5,8 @@ from rest_framework.response import Response ...@@ -5,8 +5,8 @@ from rest_framework.response import Response
from core.lib.permissions import IsAdminOrStudent, IsAdminOrCompany from core.lib.permissions import IsAdminOrStudent, IsAdminOrCompany
from core.models import Student from core.models import Student
from core.models.vacancies import Vacancy from core.models.vacancies import Vacancy, Application
from core.serializers.vacancies import VacancySerializer from core.serializers.vacancies import VacancySerializer, ApplicationSerializer
class VacancyViewSet(viewsets.ModelViewSet): class VacancyViewSet(viewsets.ModelViewSet):
...@@ -30,16 +30,18 @@ class ApplicationViewSet(viewsets.GenericViewSet): ...@@ -30,16 +30,18 @@ class ApplicationViewSet(viewsets.GenericViewSet):
return Response(vacancies.data) return Response(vacancies.data)
def create(self, request, student_id): def create(self, request, student_id):
vacancy = get_object_or_404(Vacancy.objects.all(), pk=request.data['vacancy_id']) cover_letter = request.data.get('cover_letter')
vacancy = get_object_or_404(Vacancy.objects.all(), pk=request.data.get('vacancy_id'))
student = get_object_or_404(Student.objects.all(), pk=student_id) student = get_object_or_404(Student.objects.all(), pk=student_id)
student.applied_vacancies.add(vacancy) application = Application(vacancy=vacancy, student=student, cover_letter=cover_letter)
return Response(self.serializer_class(student.applied_vacancies, many=True, context={'request': request}).data) application.save()
return Response(ApplicationSerializer(application, context={'request': request}).data)
def destroy(self, request, student_id, pk): def destroy(self, request, student_id, pk):
vacancy = get_object_or_404(Vacancy.objects.all(), pk=pk) vacancy = get_object_or_404(Vacancy.objects.all(), pk=pk)
student = get_object_or_404(Student.objects.all(), pk=student_id) student = get_object_or_404(Student.objects.all(), pk=student_id)
student.applied_vacancies.remove(vacancy) application = get_object_or_404(Application.objects.all(), student=student, vacancy=vacancy)
return Response(self.serializer_class(student.applied_vacancies, many=True, context={'request': request}).data) return Response(ApplicationSerializer(application, context={'request': request}).data)
class BookmarkedVacancyByStudentViewSet(viewsets.GenericViewSet): class BookmarkedVacancyByStudentViewSet(viewsets.GenericViewSet):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment