diff --git a/booth/migrations/0008_alter_comment_password.py b/booth/migrations/0008_alter_comment_password.py new file mode 100644 index 0000000..fb92c38 --- /dev/null +++ b/booth/migrations/0008_alter_comment_password.py @@ -0,0 +1,19 @@ +# Generated by Django 5.0.4 on 2024-05-27 00:14 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('booth', '0007_alter_boothlocationoperationtime_unique_together'), + ] + + operations = [ + migrations.AlterField( + model_name='comment', + name='password', + field=models.CharField(max_length=4, validators=[django.core.validators.RegexValidator(message='Error : Password must be a 4-digit number', regex='^\\d{4}$')]), + ), + ] diff --git a/booth/models.py b/booth/models.py index 964cbe5..fdf1edf 100644 --- a/booth/models.py +++ b/booth/models.py @@ -1,6 +1,6 @@ from django.db import models from core.models import * - +from django.core.validators import RegexValidator # Create your models here. TYPE_CHOICES=( @@ -63,7 +63,10 @@ class BoothImage(BaseImage): class Comment(models.Model): booth=models.ForeignKey(Booth, on_delete=models.CASCADE, related_name='comments') content=models.TextField() - password=models.CharField(max_length=10, null=False, blank=False) + password = models.CharField( + max_length=4, + validators=[RegexValidator(regex='^\d{4}$', message='Error : Password must be a 4-digit number')] + ) created_at=models.DateTimeField(auto_now_add=True) def __str__(self): diff --git a/booth/serializers.py b/booth/serializers.py index 222dbbd..6106313 100644 --- a/booth/serializers.py +++ b/booth/serializers.py @@ -1,5 +1,6 @@ from datetime import datetime from rest_framework import serializers +from django.core.validators import RegexValidator from.models import Booth, BoothImage, BoothLike, Comment, BoothLocationOperationTime from datetime import datetime, date @@ -188,7 +189,11 @@ class Meta: ] class CommentSerializer(serializers.ModelSerializer): - password = serializers.CharField(write_only=True) + password = serializers.CharField( + max_length=4, + validators=[RegexValidator(regex='^\d{4}$', message='Error : Password must be a 4-digit number')] + , write_only=True) + content = serializers.CharField() def create(self, validated_data): diff --git a/notice/views.py b/notice/views.py index 06f6b25..841a52c 100644 --- a/notice/views.py +++ b/notice/views.py @@ -9,7 +9,7 @@ # queryset = Notification.objects.all() class NotificationViewSet(viewsets.GenericViewSet, mixins.ListModelMixin): - queryset = Notification.objects.all() + queryset = Notification.objects.all().order_by('id') def get_serializer_class(self): if self.action == 'list': diff --git a/promo/views.py b/promo/views.py index 252df9b..28b2d58 100644 --- a/promo/views.py +++ b/promo/views.py @@ -6,7 +6,7 @@ # 디테일 페이지가 필요치 않으므로 list만 구현 class PromotionViewSet(viewsets.GenericViewSet, mixins.ListModelMixin): - queryset = Promotion.objects.all() + queryset = Promotion.objects.all().order_by('id') serializer_class = PromotionSerializer class PromotionBannerViewSet(viewsets.GenericViewSet, mixins.ListModelMixin): diff --git a/timetable/views.py b/timetable/views.py index c91b6ef..b0f1b1a 100644 --- a/timetable/views.py +++ b/timetable/views.py @@ -62,13 +62,13 @@ def get_serializer_class(self): return PerformanceSerializer class ArtistViewSet(viewsets.GenericViewSet, mixins.ListModelMixin, mixins.RetrieveModelMixin): - queryset = Artist.objects.all() + queryset = Artist.objects.all().order_by('id') serializer_class = ArtistSerializer filter_backends = [DjangoFilterBackend] filterset_class = ArtistFilter class MusicViewSet(viewsets.GenericViewSet, mixins.ListModelMixin): - queryset = Music.objects.all() + queryset = Music.objects.all().order_by('id') serializer_class = MusicSerializer class isNowPerformanceViewSet(viewsets.GenericViewSet, mixins.ListModelMixin):