From 72cd0e65a3a0b0a22288716b5ff167f4d1fad2eb Mon Sep 17 00:00:00 2001 From: chaehyeo-n Date: Thu, 26 Sep 2024 18:31:57 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Fix:=20=EB=B6=80=EC=8A=A4=20=EA=B2=BD?= =?UTF-8?q?=EB=A1=9C=EC=9D=98=20api=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/urls.py b/project/urls.py index d9360e8..979708a 100644 --- a/project/urls.py +++ b/project/urls.py @@ -20,5 +20,5 @@ urlpatterns = [ path('admin/', admin.site.urls), path('api/v1/', include('timetable.urls')), - path('', include('booth.urls')), # booth 앱의 URL을 포함 + path('api/', include('booth.urls')), # booth 앱의 URL을 포함 ] From ea5269836c6d748fbfe90810dc4f7995b5db0caf Mon Sep 17 00:00:00 2001 From: chaehyeo-n Date: Thu, 26 Sep 2024 18:32:11 +0900 Subject: [PATCH 2/3] =?UTF-8?q?Fix:=20=EB=AF=B8=EB=94=94=EC=96=B4=20?= =?UTF-8?q?=EA=B2=BD=EB=A1=9C=20=EC=A7=80=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project/settings.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/project/settings.py b/project/settings.py index b65e31d..77dd33f 100644 --- a/project/settings.py +++ b/project/settings.py @@ -18,6 +18,8 @@ BASE_DIR = Path(__file__).resolve().parent.parent STATIC_ROOT = os.path.join(BASE_DIR, 'static') +MEDIA_URL = '/media/' +MEDIA_ROOT = os.path.join(BASE_DIR, 'media') env = environ.Env(DEBUG=(bool, False)) environ.Env.read_env(os.path.join(BASE_DIR, '.env')) @@ -48,7 +50,7 @@ 'rest_framework', 'corsheaders', 'timetable', - 'booth', + 'booth', # 부스 테이블 앱 ] MIDDLEWARE = [ From c0494db66e4560767ad8608d832103c7241c3ceb Mon Sep 17 00:00:00 2001 From: chaehyeo-n Date: Thu, 26 Sep 2024 18:32:45 +0900 Subject: [PATCH 3/3] =?UTF-8?q?Feat:=20=EB=B6=80=EC=8A=A4=20=EB=94=94?= =?UTF-8?q?=ED=85=8C=EC=9D=BC=20=EB=AA=A8=EB=8D=B8=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- booth/admin.py | 5 +++-- booth/migrations/0002_boothdetail.py | 29 ++++++++++++++++++++++++++++ booth/models.py | 18 ++++++++++++++++- booth/serializers.py | 7 +++++++ booth/urls.py | 10 +++++++--- booth/views.py | 16 +++++++++------ 6 files changed, 73 insertions(+), 12 deletions(-) create mode 100644 booth/migrations/0002_boothdetail.py diff --git a/booth/admin.py b/booth/admin.py index a6157a7..453f80b 100644 --- a/booth/admin.py +++ b/booth/admin.py @@ -1,5 +1,6 @@ from django.contrib import admin -from .models import Booth +from .models import Booth, BoothDetail # Register your models here. -admin.site.register(Booth) \ No newline at end of file +admin.site.register(Booth) +admin.site.register(BoothDetail) \ No newline at end of file diff --git a/booth/migrations/0002_boothdetail.py b/booth/migrations/0002_boothdetail.py new file mode 100644 index 0000000..b129eca --- /dev/null +++ b/booth/migrations/0002_boothdetail.py @@ -0,0 +1,29 @@ +# Generated by Django 5.1.1 on 2024-09-26 18:08 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('booth', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='BoothDetail', + fields=[ + ('id', models.AutoField(primary_key=True, serialize=False)), + ('detail_description', models.TextField(blank=True)), + ('entrace_fee', models.IntegerField(default=0)), + ('menus', models.TextField(blank=True)), + ('tabling_link', models.TextField(blank=True)), + ('insta_id', models.CharField(blank=True, max_length=50)), + ('insta_link', models.TextField(blank=True)), + ('image', models.ImageField(blank=True, null=True, upload_to='booth/')), + ('like_count', models.IntegerField(default=0)), + ('booth', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='details', to='booth.booth')), + ], + ), + ] diff --git a/booth/models.py b/booth/models.py index 911c925..ffde59c 100644 --- a/booth/models.py +++ b/booth/models.py @@ -19,4 +19,20 @@ class Booth(models.Model): end_time = models.TimeField() def __str__(self): - return self.name \ No newline at end of file + return self.name + +class BoothDetail(models.Model): + id = models.AutoField(primary_key=True) # 부스 디테일의 고유 id + booth = models.OneToOneField(Booth, on_delete=models.CASCADE, related_name='details') # 부스 id를 왜래키로 참조 + detail_description = models.TextField(blank=True) # 부스 상세 설명 + entrace_fee = models.IntegerField(default=0) # 입장료 + menus = models.TextField(blank=True) # 메뉴 정보 + tabling_link = models.TextField(blank=True) # 테이블링 서비스로 이동하는 링크 + insta_id = models.CharField(max_length=50, blank=True) # 인스타그램 아이디 + insta_link = models.TextField(blank=True) # 인스타그램 링크 + image = models.ImageField(upload_to="booth/", blank=True, null=True) # 부스 이미지 + like_count = models.IntegerField(default=0) # 부스 좋아요 + + def save(self, *args, **kwargs): + self.like_count = self.booth.like_count + super().save(*args, **kwargs) \ No newline at end of file diff --git a/booth/serializers.py b/booth/serializers.py index c493b99..b3d179a 100644 --- a/booth/serializers.py +++ b/booth/serializers.py @@ -9,4 +9,11 @@ class Meta: class BoothSerializer(serializers.ModelSerializer): class Meta: model = Booth + fields = '__all__' + +class BoothDetailSerializer(serializers.ModelSerializer): + booth = serializers.PrimaryKeyRelatedField(queryset=Booth.objects.all()) + + class Meta: + model = BoothDetail fields = '__all__' \ No newline at end of file diff --git a/booth/urls.py b/booth/urls.py index 67420b5..a222cb8 100644 --- a/booth/urls.py +++ b/booth/urls.py @@ -1,6 +1,8 @@ from django.urls import path, include +from django.conf import settings +from django.conf.urls.static import static from rest_framework.routers import SimpleRouter -from .views import BoothViewSet +from .views import BoothViewSet, BoothDetailViewSet, BoothDetailListViewSet app_name = 'booth' @@ -8,5 +10,7 @@ router.register(r'booth', BoothViewSet, basename='booth') urlpatterns = [ - path('api/v1/', include(router.urls)), # 'api/v1/' 경로로 ViewSet 엔드포인트 등록 -] + path('v1/', include(router.urls)), # 'api/v1/' 경로로 ViewSet 엔드포인트 등록 + path('v1/booth/detail/', BoothDetailListViewSet.as_view(), name='booth-detail-list'), + path('v1/booth/detail//', BoothDetailViewSet.as_view(), name='booth_detail'), +] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/booth/views.py b/booth/views.py index 507e78e..7dc14f8 100644 --- a/booth/views.py +++ b/booth/views.py @@ -1,9 +1,9 @@ from django.shortcuts import render -from rest_framework import viewsets +from rest_framework import viewsets, mixins, generics from rest_framework.response import Response from rest_framework import status -from .models import Booth -from .serializers import BoothSerializer +from .models import Booth, BoothDetail +from .serializers import BoothSerializer, BoothDetailSerializer # Create your views here. from django_filters.rest_framework import DjangoFilterBackend import django_filters @@ -53,7 +53,11 @@ def get_queryset(self): return queryset +class BoothDetailViewSet(generics.RetrieveUpdateAPIView): + queryset = BoothDetail.objects.all() + serializer_class = BoothDetailSerializer + lookup_field = 'id' - - - +class BoothDetailListViewSet(generics.ListCreateAPIView): + queryset = BoothDetail.objects.all() + serializer_class = BoothDetailSerializer \ No newline at end of file