Skip to content

Commit

Permalink
chore: users 삭제를 위한 경로 변경 및 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
GalaxyDimension committed Jul 31, 2024
1 parent c40bc01 commit c66dad1
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 12 deletions.
33 changes: 33 additions & 0 deletions friends/migrations/0002_alter_friend_friend_alter_friend_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 4.2.14 on 2024-07-31 04:15

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("friends", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name="friend",
name="friend",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="friend_of",
to=settings.AUTH_USER_MODEL,
),
),
migrations.AlterField(
model_name="friend",
name="user",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="friends",
to=settings.AUTH_USER_MODEL,
),
),
]
2 changes: 1 addition & 1 deletion friends/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db import models
from users.models import User
from accounts.models import User

# Create your models here.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.14 on 2024-07-31 03:43
# Generated by Django 4.2.14 on 2024-07-31 04:31

from django.conf import settings
from django.db import migrations, models
Expand All @@ -13,7 +13,7 @@ class Migration(migrations.Migration):

operations = [
migrations.CreateModel(
name="UserRestaurantList",
name="UserRestaurantsList",
fields=[
(
"id",
Expand Down
2 changes: 1 addition & 1 deletion restaurants/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Meta:
ordering = ["-timestamp"]


class UserRestaurantList(models.Model):
class UserRestaurantsList(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
restaurant = models.ForeignKey(Restaurant, on_delete=models.CASCADE)

Expand Down
4 changes: 2 additions & 2 deletions restaurants/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from rest_framework import serializers
from .models import Restaurant, SearchHistory, UserRestaurantList
from .models import Restaurant, SearchHistory, UserRestaurantsList


class RestaurantSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -29,5 +29,5 @@ class UserRestaurantListSerializer(serializers.ModelSerializer):
restaurant = RestaurantSerializer()

class Meta:
model = UserRestaurantList
model = UserRestaurantsList
fields = "__all__"
10 changes: 5 additions & 5 deletions restaurants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework import status
from .models import Restaurant, SearchHistory, UserRestaurantList
from .models import Restaurant, SearchHistory, UserRestaurantsList
from .serializers import (
RestaurantSerializer,
RestaurantListSerializer,
Expand Down Expand Up @@ -48,7 +48,7 @@ def search(request):
@api_view(["GET"])
@login_required
def user_restaurant_list(request):
user_restaurants = UserRestaurantList.objects.filter(user=request.user)
user_restaurants = UserRestaurantsList.objects.filter(user=request.user)
serializer = UserRestaurantListSerializer(user_restaurants, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)

Expand All @@ -59,13 +59,13 @@ def add_remove_restaurant(request, pk):
try:
restaurant = Restaurant.objects.get(pk=pk)
if request.method == "POST":
UserRestaurantList.objects.create(user=request.user, restaurant=restaurant)
UserRestaurantsList.objects.create(user=request.user, restaurant=restaurant)
return Response(
{"message": "Restaurant added successfully"},
status=status.HTTP_201_CREATED,
)
elif request.method == "DELETE":
user_restaurant = UserRestaurantList.objects.get(
user_restaurant = UserRestaurantsList.objects.get(
user=request.user, restaurant=restaurant
)
user_restaurant.delete()
Expand All @@ -77,7 +77,7 @@ def add_remove_restaurant(request, pk):
return Response(
{"message": "Restaurant not found"}, status=status.HTTP_404_NOT_FOUND
)
except UserRestaurantList.DoesNotExist:
except UserRestaurantsList.DoesNotExist:
return Response(
{"message": "Restaurant not found in your list"},
status=status.HTTP_404_NOT_FOUND,
Expand Down
29 changes: 29 additions & 0 deletions reviews/migrations/0002_alter_recommend_user_alter_review_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.2.14 on 2024-07-31 04:15

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("reviews", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name="recommend",
name="user",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL
),
),
migrations.AlterField(
model_name="review",
name="user",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL
),
),
]
2 changes: 1 addition & 1 deletion reviews/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db import models
from users.models import User
from accounts.models import User
from restaurants.models import Restaurant

# Create your models here.
Expand Down

0 comments on commit c66dad1

Please sign in to comment.