Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@alfredrumss
Created April 12, 2016 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfredrumss/8aa92fccf398572380f2f2ca20b66505 to your computer and use it in GitHub Desktop.
Save alfredrumss/8aa92fccf398572380f2f2ca20b66505 to your computer and use it in GitHub Desktop.
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