diff --git a/friends/migrations/0002_alter_friend_state.py b/friends/migrations/0002_alter_friend_state.py new file mode 100644 index 0000000..c0aef6e --- /dev/null +++ b/friends/migrations/0002_alter_friend_state.py @@ -0,0 +1,24 @@ +# Generated by Django 4.2.14 on 2024-07-31 05:38 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("friends", "0001_initial"), + ] + + operations = [ + migrations.AlterField( + model_name="friend", + name="state", + field=models.CharField( + choices=[ + ("request", "Request"), + ("approve", "Approve"), + ("deny", "Deny"), + ], + max_length=20, + ), + ), + ] diff --git a/friends/migrations/0003_alter_friend_state.py b/friends/migrations/0003_alter_friend_state.py new file mode 100644 index 0000000..d469b67 --- /dev/null +++ b/friends/migrations/0003_alter_friend_state.py @@ -0,0 +1,25 @@ +# Generated by Django 4.2.14 on 2024-07-31 05:41 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("friends", "0002_alter_friend_state"), + ] + + operations = [ + migrations.AlterField( + model_name="friend", + name="state", + field=models.CharField( + choices=[ + ("request", "Request"), + ("approve", "Approve"), + ("deny", "Deny"), + ], + default="request", + max_length=20, + ), + ), + ] diff --git a/friends/models.py b/friends/models.py index 3a473bc..3f0404b 100644 --- a/friends/models.py +++ b/friends/models.py @@ -5,6 +5,12 @@ class Friend(models.Model): + STATE_CHOICES = [ + ("request", "Request"), + ("approve", "Approve"), + ("deny", "Deny"), + ] + user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="friends") friend = models.ForeignKey(User, on_delete=models.CASCADE, related_name="friend_of") - state = models.CharField(max_length=20, null=True, blank=True) + state = models.CharField(max_length=20, choices=STATE_CHOICES, default="request") diff --git a/mustgou/settings.py b/mustgou/settings.py index 321b507..3ef618c 100644 --- a/mustgou/settings.py +++ b/mustgou/settings.py @@ -42,7 +42,6 @@ "rest_framework", "rest_framework.authtoken", "accounts", - "users", "friends", "restaurants", "reviews", diff --git a/restaurants/views.py b/restaurants/views.py index 37c8509..6c478b0 100644 --- a/restaurants/views.py +++ b/restaurants/views.py @@ -20,22 +20,19 @@ def restaurant_list(request): @api_view(["GET", "POST"]) +@login_required def search(request): if request.method == "GET": - if request.user.is_authenticated: - histories = SearchHistory.objects.filter(user=request.user) - serializer = SearchHistorySerializer(histories, many=True) - return Response({"histories": serializer.data}) - else: - return Response({"error": "User not authenticated"}, status=401) + histories = SearchHistory.objects.filter(user=request.user) + serializer = SearchHistorySerializer(histories, many=True) + return Response({"histories": serializer.data}) elif request.method == "POST": query = request.data.get("query", "") if not query: return Response({"error": "No search query provided"}, status=400) - if request.user.is_authenticated: - SearchHistory.objects.create(user=request.user, query=query) + SearchHistory.objects.create(user=request.user, query=query) restaurants = Restaurant.objects.filter(name__icontains=query) serializer = RestaurantListSerializer(restaurants, many=True)