mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-16 22:09:25 +08:00
Added missing landmarks field in study group model and fixed serializer for users
This commit is contained in:
parent
bf683b08f2
commit
5af961c941
3 changed files with 31 additions and 2 deletions
20
stude/study_groups/migrations/0002_studygroup_landmark.py
Normal file
20
stude/study_groups/migrations/0002_studygroup_landmark.py
Normal file
|
@ -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'),
|
||||
),
|
||||
]
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue