mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2025-06-28 16:25:44 +08:00
Made group name unique and improved group creation functionality
This commit is contained in:
parent
032ed36af6
commit
c5f04328e5
7 changed files with 38 additions and 24 deletions
18
stude/study_groups/migrations/0003_alter_studygroup_name.py
Normal file
18
stude/study_groups/migrations/0003_alter_studygroup_name.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 4.2.5 on 2023-09-28 12:25
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('study_groups', '0002_remove_studygroup_active'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='studygroup',
|
||||
name='name',
|
||||
field=models.CharField(max_length=48, unique=True),
|
||||
),
|
||||
]
|
|
@ -6,7 +6,7 @@ from django.contrib.gis.geos import Point
|
|||
|
||||
|
||||
class StudyGroup(models.Model):
|
||||
name = models.CharField(max_length=48)
|
||||
name = models.CharField(max_length=48, unique=True)
|
||||
location = gis_models.PointField(blank=True, null=True, srid=4326)
|
||||
subject = models.ForeignKey(Subject, on_delete=models.CASCADE)
|
||||
timestamp = models.DateField(auto_now_add=True)
|
||||
|
|
|
@ -55,10 +55,11 @@ class StudyGroupCreateSerializer(serializers.ModelSerializer):
|
|||
|
||||
def update(self, instance, validated_data):
|
||||
# Check each landmark to see if our location is within it
|
||||
for landmark in Landmark.objects.all():
|
||||
if landmark.location.contains(validated_data['location']):
|
||||
validated_data['landmark'] = landmark
|
||||
break
|
||||
if ('location' in validated_data):
|
||||
for landmark in Landmark.objects.all():
|
||||
if landmark.location.contains(validated_data['location']):
|
||||
validated_data['landmark'] = landmark
|
||||
break
|
||||
return super().update(instance, validated_data)
|
||||
|
||||
class Meta:
|
||||
|
|
|
@ -31,11 +31,6 @@ class StudyGroupListView(generics.ListAPIView):
|
|||
def get_queryset(self):
|
||||
user = self.request.user
|
||||
|
||||
if not user.is_student:
|
||||
raise PermissionDenied(
|
||||
"You must be a student to view study groups"
|
||||
)
|
||||
|
||||
# Get the user's course
|
||||
user_course = user.course
|
||||
print(user_course)
|
||||
|
@ -72,19 +67,16 @@ class StudyGroupListNearView(generics.ListAPIView):
|
|||
queryset = StudyGroup.objects.all()
|
||||
|
||||
def get_queryset(self):
|
||||
|
||||
user = self.request.user
|
||||
user_status = StudentStatus.objects.filter(user=user).first()
|
||||
user_location = fromstr(
|
||||
user_status.location, srid=4326)
|
||||
|
||||
if not user.is_student:
|
||||
raise PermissionDenied(
|
||||
"You must be a student to view study groups"
|
||||
)
|
||||
|
||||
if user_status.active is False:
|
||||
raise exceptions.ValidationError("Student Status is not active")
|
||||
|
||||
user_location = fromstr(
|
||||
user_status.location, srid=4326)
|
||||
|
||||
# Get the user's course
|
||||
user_course = user.course
|
||||
print(user_course)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue