Skip to content

Commit

Permalink
Added host to usergroup when creating group and made prefs unique to …
Browse files Browse the repository at this point in the history
…user and group
  • Loading branch information
pabloj2001 committed Nov 30, 2023
1 parent c8e853a commit 7287219
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions api/optimeet/groups/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="")
Expand Down
6 changes: 4 additions & 2 deletions api/optimeet/groups/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7287219

Please sign in to comment.