Created
April 12, 2016 03:35
-
-
Save alfredrumss/8aa92fccf398572380f2f2ca20b66505 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CardsUserField(serializers.RelatedField): | |
def to_representation(self, value): | |
data = CardsSerializer(value) | |
return data.data | |
def to_internal_value(sef,data): | |
return data | |
class Meta: | |
model = Cards | |
class UserSerializer(serializers.ModelSerializer): | |
quotes = QuoteSerializer(many=True, read_only = True) | |
blogs = BlogSerializer(many=True, read_only=True) | |
comments = CommentSerializer(many=True,read_only=True) | |
password = serializers.CharField(write_only=True,required=False) | |
date_born = serializers.DateTimeField(format="%d %b %Y %I:%M%p", input_formats=None ) | |
confirm_password = serializers.CharField(write_only=True,required=False) | |
cards = CardsSerializer(many = True) | |
class Meta: | |
model = User | |
fields = ( | |
'id', | |
'username', | |
'first_name', | |
'last_name', | |
'email', | |
'user_type', | |
'direction', | |
'postal_code', | |
'city', | |
'country', | |
'password', | |
'confirm_password', | |
'date_born', | |
'image', | |
'is_superuser', | |
'is_active', | |
'cards', | |
'quotes', | |
'blogs', | |
'comments', | |
) | |
read_only_fields = ('get_full_name','quotes','blogs','comments',) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment