Skip to content

Commit

Permalink
πŸ”₯ Remove : 곡지 λ””ν…ŒμΌ νŽ˜μ΄μ§€ μ‚­μ œν•˜μ˜€μŠ΅λ‹ˆλ‹€.
Browse files Browse the repository at this point in the history
좕기단 μΈ‘ μš”μ²­μœΌλ‘œ 곡지 λ””ν…ŒμΌ νŽ˜μ΄μ§€ μ‚­μ œ ν›„ insta_url ν•„λ“œλ₯Ό μΆ”κ°€ν•˜μ—¬ μΈμŠ€νƒ€κ·Έλž¨μœΌλ‘œ 이동할 수 μžˆλ„λ‘ ν–ˆμŠ΅λ‹ˆλ‹€.
  • Loading branch information
JongbeomLee623 committed May 24, 2024
1 parent 98f4826 commit 83b8826
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 33 deletions.
18 changes: 18 additions & 0 deletions notice/migrations/0002_notification_insta_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.4 on 2024-05-24 16:08

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('notice', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='notification',
name='insta_url',
field=models.URLField(blank=True, null=True),
),
]
3 changes: 2 additions & 1 deletion notice/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class Notification(models.Model):
title = models.CharField(max_length=100)
description = models.TextField()
created_at = models.DateTimeField(auto_now_add=True)

insta_url = models.URLField(null=True, blank=True)

def __str__(self):
return self.title

Expand Down
34 changes: 5 additions & 29 deletions notice/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,41 +28,17 @@ def get_short_description(self, instance):

class Meta:
model = Notification
fields = ['id', 'title', 'short_description','description', 'created_at', 'thumbnail']
fields = ['id', 'title', 'short_description','description', 'created_at', 'thumbnail', 'insta_url']

# 곡지 λ””ν…ŒμΌ
class NotificationDetailSerializer(serializers.ModelSerializer):
images = serializers.SerializerMethodField()

def get_images(self, instance):
request = self.context.get('request')
notification_images = instance.notificationimage_set.all().order_by('id')
return [request.build_absolute_uri(image.image.url) for image in notification_images]

class Meta:
model = Notification
fields = ['id', 'title', 'description', 'created_at', 'images']

# # 곡지
# class NotificationSerializer(serializers.ModelSerializer):
# 곡지 λ””ν…ŒμΌ <- μ‚­μ œ λ˜μ—ˆμŒ.
# class NotificationDetailSerializer(serializers.ModelSerializer):
# images = serializers.SerializerMethodField()

# def get_images(self, instance):
# request = self.context.get('request')
# notification_images = instance.notificationimage_set.all().order_by('id')
# try:
# notification_image_serializer = NotificationImageSerializer(notification_images, many=True)
# outcome = []
# for data in notification_image_serializer.data:
# image_url = request.build_absolute_uri(data['image'])
# outcome.append(image_url)
# return [request.build_absolute_uri(image.image.url) for image in notification_images]

# return outcome
# except:
# return None

# class Meta:
# model = Notification
# fields = ['id', 'title', 'description', 'created_at', 'images']


6 changes: 3 additions & 3 deletions notice/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
# serializer_class = NotificationSerializer
# queryset = Notification.objects.all()

class NotificationViewSet(viewsets.GenericViewSet, mixins.ListModelMixin, mixins.RetrieveModelMixin):
class NotificationViewSet(viewsets.GenericViewSet, mixins.ListModelMixin):
queryset = Notification.objects.all()

def get_serializer_class(self):
if self.action == 'list':
return NotificationListSerializer
if self.action == 'retrieve':
return NotificationDetailSerializer
# if self.action == 'retrieve':
# return NotificationDetailSerializer
return super().get_serializer_class()

0 comments on commit 83b8826

Please sign in to comment.