22 lines
647 B
Python
22 lines
647 B
Python
|
from rest_framework import serializers
|
||
|
from django.contrib.auth.models import User
|
||
|
from .models import Todo
|
||
|
|
||
|
class UserSerializer(serializers.ModelSerializer):
|
||
|
class Meta:
|
||
|
model = User
|
||
|
fields = ('id', 'username')
|
||
|
extra_kwargs = {'password': {'write_only': True}}
|
||
|
|
||
|
def create(self, validated_data):
|
||
|
user = User.objects.create_user(
|
||
|
username=validated_data['username'],
|
||
|
password=validated_data['password']
|
||
|
)
|
||
|
return user
|
||
|
|
||
|
class TodoSerializer(serializers.ModelSerializer):
|
||
|
class Meta:
|
||
|
model = Todo
|
||
|
fields = ('id', 'title', 'completed', 'created_at')
|