Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-CloudComputing
/
C_Team_KhuDrive
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
하재연
2020-06-11 00:40:22 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d5ab7ef39534d47b1ba41aece5767daf55e8aaaa
d5ab7ef3
1 parent
b1c46779
Update serializers.py
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
10 deletions
backend/api/serializers.py
backend/api/serializers.py
View file @
d5ab7ef
from
django.contrib.auth.models
import
User
,
Group
from
rest_framework
import
serializers
from
api.models
import
Item
,
SharedItem
from
api.models
import
User
class
UserSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
UserSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
User
fields
=
[
'url'
,
'username'
,
'email'
,
'groups'
]
fields
=
'__all__'
class
SignUpSerializer
(
serializers
.
ModelSerializer
):
password2
=
serializers
.
CharField
(
style
=
{
"input_type"
:
"password"
})
class
GroupSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
model
=
Group
fields
=
[
'url'
,
'name'
]
model
=
User
fields
=
[
'user_id'
,
'name'
,
'password'
,
'password2'
]
def
create
(
self
,
data
):
user_id
=
data
[
'user_id'
]
name
=
data
[
'name'
]
password
=
self
.
data
[
'password'
]
password2
=
self
.
data
[
'password2'
]
if
user_id
and
User
.
objects
.
filter
(
user_id
=
user_id
)
.
exclude
(
name
=
name
)
.
exists
():
raise
serializers
.
ValidationError
({
"user_id"
:
"User_id must be unique."
})
class
ItemSerializer
(
serializers
.
ModelSerializer
):
elif
password
!=
password2
:
raise
serializers
.
ValidationError
({
'password'
:
"Passwords must match."
})
user
=
User
.
objects
.
create
(
user_id
=
data
[
'user_id'
],
name
=
data
[
'name'
],
password
=
data
[
'password'
],
)
user
.
save
()
return
user
class
UserInfoSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Item
fields
=
'__all__'
model
=
User
fields
=
[
'user_id'
,
'name'
,
'total_size'
,
'current_size'
]
...
...
Please
register
or
login
to post a comment