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-11-10 20:14:30 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
edbb57b8793a82fc7378db87ae26cdb3bc83cb91
edbb57b8
1 parent
3fb97a27
delete door_id in setting api
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
13 deletions
api/migrations/0001_initial.py
api/migrations/0002_auto_20201110_1944.py
api/models.py
api/views.py
api/migrations/0001_initial.py
0 → 100644
View file @
edbb57b
# Generated by Django 3.1.2 on 2020-11-04 11:24
from
django.db
import
migrations
,
models
import
django.db.models.deletion
import
django.utils.timezone
class
Migration
(
migrations
.
Migration
):
initial
=
True
dependencies
=
[
]
operations
=
[
migrations
.
CreateModel
(
name
=
'Device'
,
fields
=
[
(
'rfid_id'
,
models
.
CharField
(
max_length
=
255
,
primary_key
=
True
,
serialize
=
False
)),
(
'created'
,
models
.
DateTimeField
(
default
=
django
.
utils
.
timezone
.
now
)),
],
),
migrations
.
CreateModel
(
name
=
'Door'
,
fields
=
[
(
'door_id'
,
models
.
CharField
(
max_length
=
255
,
primary_key
=
True
,
serialize
=
False
)),
],
),
migrations
.
CreateModel
(
name
=
'History'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'device_name'
,
models
.
CharField
(
max_length
=
255
)),
(
'ctrtime'
,
models
.
DateTimeField
(
default
=
django
.
utils
.
timezone
.
now
)),
],
),
migrations
.
CreateModel
(
name
=
'Video'
,
fields
=
[
(
'vid_id'
,
models
.
IntegerField
(
primary_key
=
True
,
serialize
=
False
)),
(
'created'
,
models
.
DateTimeField
(
default
=
django
.
utils
.
timezone
.
now
)),
(
's3_link'
,
models
.
CharField
(
max_length
=
255
)),
],
),
migrations
.
CreateModel
(
name
=
'Record'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'recording'
,
models
.
BooleanField
(
default
=
True
)),
(
'door'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'api.door'
)),
],
),
migrations
.
CreateModel
(
name
=
'Lock'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'state'
,
models
.
BooleanField
(
default
=
True
)),
(
'door'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'api.door'
)),
],
),
]
api/migrations/0002_auto_20201110_1944.py
0 → 100644
View file @
edbb57b
# Generated by Django 3.1.2 on 2020-11-10 10:44
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'api'
,
'0001_initial'
),
]
operations
=
[
migrations
.
RemoveField
(
model_name
=
'lock'
,
name
=
'door'
,
),
migrations
.
RemoveField
(
model_name
=
'record'
,
name
=
'door'
,
),
migrations
.
AlterField
(
model_name
=
'lock'
,
name
=
'id'
,
field
=
models
.
IntegerField
(
primary_key
=
True
,
serialize
=
False
),
),
migrations
.
AlterField
(
model_name
=
'record'
,
name
=
'id'
,
field
=
models
.
IntegerField
(
primary_key
=
True
,
serialize
=
False
),
),
]
api/models.py
View file @
edbb57b
...
...
@@ -16,7 +16,7 @@ class Video(models.Model) :
s3_link
=
models
.
CharField
(
max_length
=
255
)
class
Lock
(
models
.
Model
)
:
door
=
models
.
ForeignKey
(
Door
,
on_delete
=
models
.
CASCADE
)
id
=
models
.
IntegerField
(
primary_key
=
True
)
state
=
models
.
BooleanField
(
default
=
True
)
class
History
(
models
.
Model
)
:
...
...
@@ -24,5 +24,5 @@ class History(models.Model) :
ctrtime
=
models
.
DateTimeField
(
default
=
timezone
.
now
)
class
Record
(
models
.
Model
)
:
door
=
models
.
ForeignKey
(
Door
,
on_delete
=
models
.
CASCADE
)
id
=
models
.
IntegerField
(
primary_key
=
True
)
recording
=
models
.
BooleanField
(
default
=
True
)
\ No newline at end of file
...
...
api/views.py
View file @
edbb57b
...
...
@@ -94,14 +94,10 @@ class CheckDate(APIView) :
class
Recording
(
APIView
)
:
def
get
(
self
,
request
,
format
=
None
)
:
try
:
'''
request_id = request.GET.get('door_id')
target = Record.objects.filter(door_id = request_id)
'''
target
=
Record
.
objects
.
all
()
serializer
=
RecordSerializer
(
target
,
many
=
True
)
target
=
Record
.
objects
.
get
(
id
=
1
)
serializer
=
RecordSerializer
(
target
,
many
=
False
)
res
=
{
'recording'
:
serializer
.
data
'recording'
:
serializer
.
data
[
'recording'
]
}
return
Response
(
res
,
status
=
status
.
HTTP_200_OK
)
except
FieldDoesNotExist
as
error
:
...
...
@@ -112,10 +108,7 @@ class Recording(APIView) :
def
put
(
self
,
request
,
format
=
None
)
:
try
:
request_id
=
request
.
GET
.
get
(
'door_id'
)
if
not
request_id
:
raise
FieldDoesNotExist
target
=
Record
.
objects
.
filter
(
door_id
=
request_id
)
target
=
Record
.
objects
.
filter
(
id
=
1
)
target
.
update
(
recording
=
request
.
data
[
'recording'
])
return
Response
(
status
=
status
.
HTTP_200_OK
)
except
FieldDoesNotExist
as
error
:
...
...
Please
register
or
login
to post a comment