-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserializers.py
89 lines (82 loc) · 3.47 KB
/
serializers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from rest_framework import serializers
from todoapp.models import *
class TodolistsSerializer(serializers.ModelSerializer):
class Meta:
model = Todolists
fields = ('id','name', 'creation_date','user')
class TodoitemsSerializer(serializers.ModelSerializer):
class Meta:
model = Todoitems
fields = ('id','description', 'completed','todolist', 'due_by')
# from django.contrib.auth import update_session_auth_hash
# from rest_framework import serializers
#
# from .models import Account
#
#
# class AccountSerializer(serializers.ModelSerializer):
# password = serializers.CharField(write_only=True, required=True)
# confirm_password = serializers.CharField(write_only=True, required=True)
# class Meta:
# model = Account
# fields = (
# 'id', 'email', 'username', 'date_created', 'date_modified',
# 'firstname', 'lastname', 'password', 'confirm_password')
# read_only_fields = ('date_created', 'date_modified')
#
# def create(self, validated_data):
# return Account.objects.create_user(**validated_data)
#
# def update(self, instance, validated_data):
# instance.email = validated_data.get('email', instance.email)
# instance.username = validated_data.get('username',
# instance.username)
# instance.firstname = validated_data.get('firstname',
# instance.firstname)
# instance.lastname = validated_data.get('lastname',
# instance.lastname)
#
# password = validated_data.get('password', None)
# confirm_password = validated_data.get('confirm_password', None)
#
# if password and password == confirm_password:
# instance.set_password(password)
#
# instance.save()
# return instance
#
# def validate(self, data):
# '''
# Ensure the passwords are the same
# '''
# if data['password']:
# print "Here"
# if data['password'] != data['confirm_password']:
# raise serializers.ValidationError(
# "The passwords have to be the same"
# )
# return data
#
#
# class StudentSerializer(serializers.Serializer):
# id = serializers.IntegerField(read_only=True)
# name = serializers.CharField(required=False, allow_blank=True, max_length=100)
# email = serializers.EmailField()
# db_folder = serializers.CharField(required=False)
#
# def create(self, validated_data):
# """
# Create and return a new `Snippet` instance, given the validated data.
# """
# return Student.objects.create(**validated_data)
#
# def update(self, instance, validated_data):
# """
# Update and return an existing `Snippet` instance, given the validated data.
# """
# instance.id = validated_data.get('id', instance.id)
# instance.name = validated_data.get('name', instance.name)
# instance.email = validated_data.get('email', instance.email)
# instance.db_folder = validated_data.get('db_folder', instance.db_folder)
# instance.save()
# return instance