최지우

edit api restful and add database

......@@ -12,3 +12,10 @@ class Video(models.Model) :
vidname = models.CharField(max_length = 255, primary_key = True)
created = models.DateTimeField(default = timezone.now)
s3_link = models.CharField(max_length = 255)
class Lock(models.Model) :
state = models.BooleanField(default = True)
class History(models.Model) :
device = ForeignKey(Device, on_delete=models.CASCADE)
ctrtime = created = models.DateTimeField(default = timezone.now)
\ No newline at end of file
......
from api.models import Phone, Video
from api.models import Device, Video, History
from rest_framework import serializers
class PhoneSerializer(serializers.ModelSerializer) :
class DeviceSerializer(serializers.ModelSerializer) :
class Meta :
model = Device
fields = '__all__'
......@@ -11,3 +11,8 @@ class VideoSerializer(serializers.ModelSerializer) :
class Meta :
model = Video
fields = '__all__'
class HistorySerializer(serializers.ModelSerializer) :
class Meta :
model = History
fields = '__all__'
\ No newline at end of file
......
......@@ -44,7 +44,7 @@ class Video(APIView) :
'date' : datetime.now()
}, status = status.HTTP_404_NOT_FOUND)
def post(self, request, format = None) :
def delete(self, request, format = None) :
try :
request_id = request.GET.get('vidname')
if request_id == 'None' :
......@@ -63,7 +63,7 @@ class Video(APIView) :
}, status = status.HTTP_400_BAD_REQUEST)
class CheckDate(APIView) :
def post(self, request, format = None) :
def delete(self, request, format = None) :
checkdate = datetime.now() + timedelta(days = -7)
quaryset = Video.objects.filter(created__lt = checkdate)
session = boto3.session.Session(aws_access_key_id = S3_ACCESS_KEY_ID, aws_secret_access_key = S3_SECRET_ACCESS_KEY, region_name = AWS_REGION)
......
......@@ -20,6 +20,6 @@ from api import views
urlpatterns = [
path('admin/', admin.site.urls),
path('api/video/', views.Video.as_view()),
path('api/videoAutoDelete/', views.CheckDate.as_view()),
path('api/video/<str:vidname>/', views.Video.as_view()),
path('api/checkDate/', views.CheckDate.as_view()),
]
......