Commit 90a4e285 authored by Fernando Ribeiro's avatar Fernando Ribeiro
Browse files

Fix: changed relation in courses models and add serializers

parent 3fbe0cdb
# Generated by Django 2.2.12 on 2020-06-08 14:02
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('auth', '0011_update_proxy_permissions'),
('courses', '0007_auto_20200512_2349'),
]
operations = [
migrations.AddField(
model_name='professormessage',
name='classes',
field=models.ManyToManyField(blank=True, related_name='message_courses', to='courses.Class', verbose_name='Default Class'),
),
migrations.AddField(
model_name='professormessage',
name='groups',
field=models.ManyToManyField(blank=True, help_text='The Groups that will receive this message.', related_name='message_groups', to='auth.Group', verbose_name='groups'),
),
]
......@@ -652,15 +652,13 @@ class ProfessorMessage(models.Model):
Group,
verbose_name=_('groups'),
blank=True,
help_text=_('The Groups that can have access to this forum. If empty, there are no group restrictions.'),
related_name="courses",
help_text=_('The Groups that will receive this message.'),
related_name="message_groups",
)
default_class = models.ManyToManyField(
classes = models.ManyToManyField(
'Class',
models.SET_NULL,
verbose_name=_('Default Class'),
related_name='default_course',
null=True,
related_name='message_courses',
blank=True,
)
......
......@@ -123,12 +123,13 @@ class ProfessorMessageSerializer(serializers.ModelSerializer):
course_slug = serializers.SerializerMethodField(read_only=True)
course_name = serializers.SerializerMethodField(read_only=True)
is_read = serializers.SerializerMethodField(read_only=True)
groups = self.context['request'].data.get('groups', None)
groups = serializers.SerializerMethodField(read_only=True)
classes = serializers.SerializerMethodField(read_only=True)
class Meta:
model = ProfessorMessage
fields = ('id', 'course', 'course_name', 'course_slug', 'professor',
'users', 'subject', 'message', 'date', 'is_read')
'users', 'subject', 'message', 'date', 'is_read','groups', 'classes')
def get_course_slug(self, obj):
try:
......
Markdown is supported
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