File tree Expand file tree Collapse file tree 11 files changed +110
-0
lines changed Expand file tree Collapse file tree 11 files changed +110
-0
lines changed Original file line number Diff line number Diff line change 44
44
"constance.backends.database" ,
45
45
# apps
46
46
"sponsor" ,
47
+ "status" ,
47
48
# swagger
48
49
"drf_spectacular" ,
49
50
]
Original file line number Diff line number Diff line change 23
23
)
24
24
25
25
import sponsor .routers
26
+ import status .urls
26
27
27
28
urlpatterns = [
28
29
path ("api-auth/" , include ("rest_framework.urls" )),
29
30
path ("summernote/" , include ("django_summernote.urls" )),
30
31
path ("admin/" , admin .site .urls ),
31
32
path ("sponsors/" , include (sponsor .routers .get_router ().urls )),
33
+ path ("status/" , include (status .urls )),
32
34
]
33
35
34
36
if settings .DEBUG is True :
Original file line number Diff line number Diff line change
1
+ from django .contrib import admin
2
+
3
+ from status .models import Status
4
+
5
+
6
+ class StatusAdmin (admin .ModelAdmin ):
7
+ list_display = ("name" , "open_at" , "close_at" )
8
+ list_editable = (
9
+ "open_at" ,
10
+ "close_at" ,
11
+ )
12
+ ordering = ("open_at" ,)
13
+ search_fields = ("name" ,)
14
+
15
+
16
+ admin .site .register (Status , StatusAdmin )
Original file line number Diff line number Diff line change
1
+ from django .apps import AppConfig
2
+
3
+
4
+ class StatusConfig (AppConfig ):
5
+ default_auto_field = "django.db.models.BigAutoField"
6
+ name = "status"
Original file line number Diff line number Diff line change
1
+ # Generated by Django 4.1.5 on 2023-02-24 17:43
2
+
3
+ from django .db import migrations , models
4
+
5
+
6
+ class Migration (migrations .Migration ):
7
+
8
+ initial = True
9
+
10
+ dependencies = []
11
+
12
+ operations = [
13
+ migrations .CreateModel (
14
+ name = "Status" ,
15
+ fields = [
16
+ (
17
+ "id" ,
18
+ models .BigAutoField (
19
+ auto_created = True ,
20
+ primary_key = True ,
21
+ serialize = False ,
22
+ verbose_name = "ID" ,
23
+ ),
24
+ ),
25
+ ("name" , models .CharField (max_length = 100 )),
26
+ ("open_at" , models .DateTimeField ()),
27
+ ("close_at" , models .DateTimeField ()),
28
+ ],
29
+ ),
30
+ ]
Original file line number Diff line number Diff line change
1
+ from django .db import models
2
+
3
+
4
+ class Status (models .Model ):
5
+ name = models .CharField (max_length = 100 )
6
+ open_at = models .DateTimeField ()
7
+ close_at = models .DateTimeField ()
Original file line number Diff line number Diff line change
1
+ from django .test import TestCase
2
+
3
+ # Create your tests here.
Original file line number Diff line number Diff line change
1
+ """pyconkr URL Configuration
2
+
3
+ The `urlpatterns` list routes URLs to views. For more information please see:
4
+ https://docs.djangoproject.com/en/4.1/topics/http/urls/
5
+ Examples:
6
+ Function views
7
+ 1. Add an import: from my_app import views
8
+ 2. Add a URL to urlpatterns: path('', views.home, name='home')
9
+ Class-based views
10
+ 1. Add an import: from other_app.views import Home
11
+ 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12
+ Including another URLconf
13
+ 1. Import the include() function: from django.urls import include, path
14
+ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15
+ """
16
+ from django .contrib import admin
17
+ from django .urls import include , path
18
+
19
+ from status .views import StatusView
20
+
21
+ urlpatterns = [
22
+ path ("<str:name>" , StatusView .as_view ()),
23
+ ]
Original file line number Diff line number Diff line change
1
+ import datetime
2
+
3
+ from pytz import timezone
4
+ from rest_framework .response import Response
5
+ from rest_framework .views import APIView
6
+
7
+ from status .models import Status
8
+
9
+
10
+ class StatusView (APIView ):
11
+ def get (self , request , name : str ):
12
+ status = Status .objects .get (name = name )
13
+ now = datetime .datetime .now (tz = timezone ("Asia/Seoul" ))
14
+
15
+ flag = None
16
+
17
+ if status .open_at < now < status .close_at :
18
+ flag = True
19
+ else :
20
+ flag = False
21
+
22
+ return Response ({"name" : name , "open" : flag })
You can’t perform that action at this time.
0 commit comments