Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 유저 프로필 이미지 이름 수정 #103

Merged
merged 4 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion accounts/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
import os
from django.conf import settings
from django.db import models
from django.contrib.auth.models import AbstractUser
from django.core.files.storage import FileSystemStorage


def profile_img_upload_to(instance, filename):
return f"profile_img/{instance.id}.jpg"


class OverwriteStorage(FileSystemStorage):
def get_aavailable_name(self, name):
if self.exists(name):
os.remove(os.path.join(settings.MEDIA_ROOT, name))
return name


class User(AbstractUser):
Expand All @@ -13,7 +27,9 @@ class User(AbstractUser):
)

profile_img = models.ImageField(
default="default_profile_img.jpg", upload_to="profile_img/"
default="default_profile_img.jpg",
upload_to=profile_img_upload_to,
storage=OverwriteStorage(),
)

reliability = models.SmallIntegerField(default=80)
Expand Down
3 changes: 3 additions & 0 deletions accounts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ class Meta:

def get_friend_count(self, obj):
return Friend.objects.filter(user=obj).count()

def update(self, instance, validated_data):
return super().update(instance, validated_data)
2 changes: 1 addition & 1 deletion friends/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def friend_restaurant_list(request, pk):
{
"message": "Friend evaluated successfully",
"reliability": friend.reliability,
"is_Evaluated": Friend.objects.get(
"is_evaluated": Friend.objects.get(
user=request.user, friend=friend
).is_evaluated,
},
Expand Down
Loading