Skip to content

Commit

Permalink
Fixed small bugs - Edit user's interest
Browse files Browse the repository at this point in the history
  • Loading branch information
sidarragac committed Nov 8, 2024
1 parent f56bc9d commit cc3912f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,20 @@ def interestSelection(request):
interest = request.POST.get(f'interest{i+1}')
if interest:
interests.append(interest)

for interest in interests:
if UserInterest.objects.filter(user=user, interest=interest).exists():
continue
UserInterest.objects.create(user=user, interest=interest)
UserInterest.objects.create(user=user, interest=Interest.objects.get(id=interest))

if UserInterest.objects.filter(user=user).count() > 3:
UserInterest.objects.exclude(interest_in=interests).delete()
if UserInterest.objects.filter(user=user).count() != len(interests):
UserInterest.objects.filter(user=user).exclude(interest__in=interests).delete()

return redirect('profile')

@login_required
def editInterests(request):
userInterests = UserInterest.objects.filter(user=request.user)
userInterests = list(UserInterest.objects.filter(user=request.user).values_list('interest', flat=True))
interests = Interest.objects.all()

while len(userInterests) < 3:
Expand Down

0 comments on commit cc3912f

Please sign in to comment.