diff --git a/stude/study_groups/migrations/0002_studygroup_landmark.py b/stude/study_groups/migrations/0002_studygroup_landmark.py new file mode 100644 index 0000000..c056a83 --- /dev/null +++ b/stude/study_groups/migrations/0002_studygroup_landmark.py @@ -0,0 +1,20 @@ +# Generated by Django 4.2.3 on 2023-09-24 10:59 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('landmarks', '0001_initial'), + ('study_groups', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='studygroup', + name='landmark', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='landmarks.landmark'), + ), + ] diff --git a/stude/study_groups/models.py b/stude/study_groups/models.py index 9aa761e..89e1d51 100644 --- a/stude/study_groups/models.py +++ b/stude/study_groups/models.py @@ -13,6 +13,8 @@ class StudyGroup(models.Model): subject = models.ForeignKey(Subject, on_delete=models.CASCADE) active = models.BooleanField(default=False) timestamp = models.DateField(auto_now_add=True) + landmark = models.ForeignKey( + 'landmarks.Landmark', on_delete=models.SET_NULL, null=True) def __str__(self): return self.name diff --git a/stude/study_groups/serializers.py b/stude/study_groups/serializers.py index 19cdec3..2362576 100644 --- a/stude/study_groups/serializers.py +++ b/stude/study_groups/serializers.py @@ -6,9 +6,16 @@ from drf_extra_fields.geo_fields import PointField from landmarks.models import Landmark +class CustomUserKeyRelatedField(serializers.PrimaryKeyRelatedField): + + def to_representation(self, value): + # returns the string representation of the custom user (aka the name) + return str(value) + + class StudyGroupSerializer(serializers.ModelSerializer): - users = serializers.SlugRelatedField( - queryset=CustomUser.objects.all(), many=True, slug_field='full_name', required=False, allow_null=True) + users = CustomUserKeyRelatedField( + queryset=CustomUser.objects.all(), many=True) subject = serializers.SlugRelatedField( many=False, slug_field='name', queryset=Subject.objects.all(), required=True, allow_null=False) location = PointField()