From a0998032c7d0e5c53bbb319ddff6169af93dbb5b Mon Sep 17 00:00:00 2001 From: Kevin Albert Simanjuntak <kevinjuntak51@gmail.com> Date: Fri, 15 Nov 2019 20:31:08 +0700 Subject: [PATCH 1/2] Menambahkan field student, company pada model feedback --- core/migrations/0002_auto_20191115_2030.py | 26 ++++++++++++++++++++++ core/models/feedbacks.py | 4 +++- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 core/migrations/0002_auto_20191115_2030.py diff --git a/core/migrations/0002_auto_20191115_2030.py b/core/migrations/0002_auto_20191115_2030.py new file mode 100644 index 00000000..1b420d2b --- /dev/null +++ b/core/migrations/0002_auto_20191115_2030.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.17 on 2019-11-15 13:30 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='feedback', + name='companyId', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='core.Company'), + ), + migrations.AddField( + model_name='feedback', + name='studentId', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='core.Student'), + ), + ] diff --git a/core/models/feedbacks.py b/core/models/feedbacks.py index c473ae82..1b9293b0 100755 --- a/core/models/feedbacks.py +++ b/core/models/feedbacks.py @@ -1,10 +1,12 @@ from django.db import models - +from core.models.accounts import Student, Company class Feedback(models.Model): created = models.DateTimeField(auto_now_add=True) title = models.CharField(max_length=100, blank=True, default='') content = models.TextField() + studentId = models.ForeignKey(Student, on_delete=models.CASCADE, null=True) + companyId = models.ForeignKey (Company, on_delete=models.CASCADE, null=True) class Meta: ordering = ['created'] -- GitLab From da95517f9efbf6bcb2e1db0f45fd682bb368bc89 Mon Sep 17 00:00:00 2001 From: Kevin Albert Simanjuntak <kevinjuntak51@gmail.com> Date: Fri, 15 Nov 2019 20:36:48 +0700 Subject: [PATCH 2/2] Mengubah serializer agar studentId dan companyId muncul pada saat nge post --- core/serializers/feedbacks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/serializers/feedbacks.py b/core/serializers/feedbacks.py index 25587307..59006181 100755 --- a/core/serializers/feedbacks.py +++ b/core/serializers/feedbacks.py @@ -6,4 +6,4 @@ from core.models.feedbacks import Feedback class FeedbackSerializer(serializers.ModelSerializer): class Meta: model = Feedback - fields = ['id', 'title', 'content'] + fields = '__all__' -- GitLab