diff --git a/api/optimeet/groups/models.py b/api/optimeet/groups/models.py index 9f4cf66..b594e1b 100644 --- a/api/optimeet/groups/models.py +++ b/api/optimeet/groups/models.py @@ -46,6 +46,9 @@ class Preferences(models.Model): lon = models.FloatField() radius = models.FloatField() + class Meta: + unique_together = [["group_id", "user_id"]] + class Votes(models.Model): rec_id = models.ForeignKey(Recommendations, on_delete=models.DO_NOTHING) group_id = models.ForeignKey(Group, on_delete=models.DO_NOTHING, default="") diff --git a/api/optimeet/groups/views.py b/api/optimeet/groups/views.py index 6848c47..4520cdb 100644 --- a/api/optimeet/groups/views.py +++ b/api/optimeet/groups/views.py @@ -21,8 +21,10 @@ def groups(request): serializer = serializers.GroupSerializer(data = request.data) if serializer.is_valid(): - serializer.save() - + group = serializer.save() + usergroup = models.UserGroup(user_id=group.host_id, group_id=group) + usergroup.save() + return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)