Skip to content

Commit

Permalink
Merge pull request #108 from dudtlstm/main
Browse files Browse the repository at this point in the history
🩹 Fix: settings.py renderer 추가
  • Loading branch information
dudtlstm authored Oct 7, 2024
2 parents 07c9458 + 5cb367a commit 947a1b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
17 changes: 11 additions & 6 deletions booth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@ class Booth(models.Model):
open_time = models.DateTimeField(verbose_name="시작 시간")
close_time = models.DateTimeField(verbose_name="마감 시간")

def save(self, *args, **kwargs):
if self.is_operated == 'operating' and self.open_time is None:
self.open_time = timezone.now()
elif self.is_operated == 'finished' and self.close_time is None:
self.close_time = timezone.now()
super().save(*args, **kwargs)
@property
def is_operated(self):
current_time = timezone.now()
if self.open_time and self.close_time:
if self.open_time <= current_time < self.close_time:
return 'operating' # 운영 시간 내이면 '운영 중'
elif current_time >= self.close_time:
return 'finished' # 마감 시간을 넘겼으면 '운영 종료'
else:
return 'not_started' # 아직 시작 시간이 되지 않았으면 '운영 전'
return 'not_started'

def __str__(self):
return self.name
Expand Down
3 changes: 3 additions & 0 deletions linenow/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
),
'EXCEPTION_HANDLER': 'utils.exceptions.custom_exception_handler',
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'],
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
),
}

REST_AUTH = {
Expand Down

0 comments on commit 947a1b2

Please sign in to comment.