Toggle navigation
Toggle navigation
This project
Loading...
Sign in
cse437_e
/
smartdoorlock-backend
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
최지우
2020-10-20 19:45:40 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
0258df7eec9f1aac3e8b46b316f3cf94fbe63bbd
0258df7e
1 parent
93b922c1
edit api restful and add database
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
6 deletions
api/models.py
api/serializers.py
api/views.py
src/urls.py
api/models.py
View file @
0258df7
...
...
@@ -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
...
...
api/serializers.py
View file @
0258df7
from
api.models
import
Phone
,
Video
from
api.models
import
Device
,
Video
,
History
from
rest_framework
import
serializers
class
Phon
eSerializer
(
serializers
.
ModelSerializer
)
:
class
Devic
eSerializer
(
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
...
...
api/views.py
View file @
0258df7
...
...
@@ -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
)
...
...
src/urls.py
View file @
0258df7
...
...
@@ -20,6 +20,6 @@ from api import views
urlpatterns
=
[
path
(
'admin/'
,
admin
.
site
.
urls
),
path
(
'api/video/'
,
views
.
Video
.
as_view
()),
path
(
'api/
videoAutoDele
te/'
,
views
.
CheckDate
.
as_view
()),
path
(
'api/video/
<str:vidname>/
'
,
views
.
Video
.
as_view
()),
path
(
'api/
checkDa
te/'
,
views
.
CheckDate
.
as_view
()),
]
...
...
Please
register
or
login
to post a comment